Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! An example showing off the usage of `Deserialize` to automatically decode
- //! TOML into a Rust `struct`
- #![deny(warnings)]
- extern crate toml;
- #[macro_use]
- extern crate serde_derive;
- #[derive(Debug, Deserialize)]
- struct Tasks {
- items: Option<Vec<Task>>,
- }
- #[derive(Deserialize, Debug)]
- struct Task {
- id: String,
- field: String,
- }
- fn main() {
- let toml_str = r#"
- [[items]]
- id = "todo"
- field = "something"
- [[items]]
- id = "todo"
- field = "something"
- "#;
- let entry = Task { id: "1".to_string(), field: "Test encoding".to_string() };
- let decoded: Tasks = toml::from_str(toml_str).unwrap();
- let encoded = toml::to_string(&entry).unwrap();
- println!("{:#?}", encoded);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement