mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 18:44:07 +02:00
serde example
This commit is contained in:
parent
cf2fda0c8c
commit
0090bea796
2 changed files with 21 additions and 0 deletions
21
examples/serde.rs
Normal file
21
examples/serde.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
use php_literal_parser::{from_str, ParseError};
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
|
struct Target {
|
||||||
|
foo: bool,
|
||||||
|
bars: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), ParseError> {
|
||||||
|
let target = from_str(r#"["foo" => true, "bars" => [1, 2, 3, 4,]]"#)?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Target {
|
||||||
|
foo: true,
|
||||||
|
bars: vec![1, 2, 3, 4]
|
||||||
|
},
|
||||||
|
target
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue