serde example

This commit is contained in:
Robin Appelman 2020-12-14 00:13:00 +01:00
commit 0090bea796
2 changed files with 21 additions and 0 deletions

21
examples/serde.rs Normal file
View 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(())
}