Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Created March 22, 2016 00:28
Show Gist options
  • Select an option

  • Save cengiz-io/9cd3c9fcd124b36af86a to your computer and use it in GitHub Desktop.

Select an option

Save cengiz-io/9cd3c9fcd124b36af86a to your computer and use it in GitHub Desktop.
#![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