commit | a81e0c4f1e41839406542838c024606cde4883fc | [log] [tgz] |
---|---|---|
author | Callum Oakley <c.oakley108@gmail.com> | Fri Apr 03 16:49:04 2020 +0100 |
committer | GitHub <noreply@github.com> | Fri Apr 03 16:49:04 2020 +0100 |
tree | c82bba865f3739a09ea94d9de24029f1cb0ab64b | |
parent | 429b6b26c0fd5b048aee48a72f76b9f504adc4cf [diff] | |
parent | a45370d3b8ccbaa4e64e9cbebe7a52530fa309fe [diff] |
Merge pull request #18 from acanthite/fix-empty-variants-panic Add correct handling of empty struct and empty tuple variants
A Rust JSON5 serializer and deserializer which speaks Serde.
Deserialize a JSON5 string with from_str
. Go the other way with to_string
. The serializer is very basic at the moment, it just produces plain old JSON. See the Serde documentation for details on implementing Serialize
and Deserialize
. (Usually it's just a case of sprinkling in some derives.)
The Serde data model is mostly supported, with the exception of bytes and borrowed strings.
Read some config into a struct.
use json5; use serde_derive::Deserialize; #[derive(Deserialize, Debug, PartialEq)] struct Config { message: String, n: i32, } fn main() { let config = " { // A traditional message. message: 'hello world', // A number for some reason. n: 42, } "; assert_eq!( json5::from_str(config), Ok(Config { message: "hello world".to_string(), n: 42, }), ); }