chiark / gitweb /
make install
[talk-2019-ghm-rust.git] / serde-example.txt
1 use serde::{Serialize, Deserialize};
2
3 #[derive(Serialize, Deserialize, Debug)]
4 struct Point { x: i32, y: i32, }
5
6 fn main() {
7     let point = Point { x: 1, y: 2 };
8
9     // Convert the Point to a JSON string.
10     let j = serde_json::to_string(&point).unwrap();
11
12     // Parse the JSON string as a Point.
13     let p2: Point = serde_json::from_str(&j).unwrap();