diff options
author | Alex Crichton <alex@alexcrichton.com> | 2017-02-08 21:23:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-08 21:23:29 -0800 |
commit | beff7f992d738db3565d899a72542baae57f835d (patch) | |
tree | 76498b837fc5f1f6ba0a5f53e1b2d85c6638da4d /examples/decode.rs | |
parent | 473908c9722eeedeec1777237a135f582faa78d8 (diff) | |
parent | f66d8bcf33530c858a502bfa170f2383a8cbc204 (diff) | |
download | milf-rs-beff7f992d738db3565d899a72542baae57f835d.tar.gz milf-rs-beff7f992d738db3565d899a72542baae57f835d.zip |
Merge pull request #137 from alexcrichton/serde-upgrade
Rewrite crate with serde support from ground up
Diffstat (limited to 'examples/decode.rs')
-rw-r--r-- | examples/decode.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/examples/decode.rs b/examples/decode.rs index 9124596..8390e15 100644 --- a/examples/decode.rs +++ b/examples/decode.rs @@ -1,4 +1,4 @@ -//! An example showing off the usage of `RustcDecodable` to automatically decode +//! An example showing off the usage of `Deserialize` to automatically decode //! TOML into a Rust `struct` //! //! Note that this works similarly with `serde` as well. @@ -6,11 +6,12 @@ #![deny(warnings)] extern crate toml; -extern crate rustc_serialize; +#[macro_use] +extern crate serde_derive; /// This is what we're going to decode into. Each field is optional, meaning /// that it doesn't have to be present in TOML. -#[derive(Debug, RustcDecodable)] +#[derive(Debug, Deserialize)] struct Config { global_string: Option<String>, global_integer: Option<u64>, @@ -22,13 +23,13 @@ struct Config { /// table. /// /// Again, each field is optional, meaning they don't have to be present. -#[derive(Debug, RustcDecodable)] +#[derive(Debug, Deserialize)] struct ServerConfig { ip: Option<String>, port: Option<u64>, } -#[derive(Debug, RustcDecodable)] +#[derive(Debug, Deserialize)] struct PeerConfig { ip: Option<String>, port: Option<u64>, @@ -51,11 +52,6 @@ fn main() { ip = "127.0.0.1" "#; - // Use the `decode_str` convenience here to decode a TOML string directly - // into the `Config` struct. - // - // Note that the errors reported here won't necessarily be the best, but you - // can get higher fidelity errors working with `toml::Parser` directly. - let decoded: Config = toml::decode_str(toml_str).unwrap(); + let decoded: Config = toml::from_str(toml_str).unwrap(); println!("{:#?}", decoded); } |