Created
March 22, 2016 00:28
-
-
Save cengiz-io/9cd3c9fcd124b36af86a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![feature(custom_derive, plugin)] | |
| #![plugin(serde_macros)] | |
| extern crate serde; | |
| extern crate serde_json; | |
| #[derive(Serialize, Deserialize, Debug)] | |
| struct Point { | |
| x: i32, | |
| y: i32, | |
| } | |
| #[derive(Serialize, Deserialize, Debug)] | |
| struct Line { | |
| start: Line, | |
| end: Line, | |
| } | |
| fn main() { | |
| let line = Line { start: Point { x: 1, y: 2 }, end: Point { x: 11, y: 12} }; | |
| let serialized = serde_json::to_string(&line).unwrap(); | |
| println!("{}", serialized); | |
| let deserialized: Line = serde_json::from_str(&serialized).unwrap(); | |
| println!("{:?}", deserialized); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment