Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //use serde::{Serialize, Deserialize};
  2. use serde_cbor::{Serialize, Deserialize};
  3.  
  4. #[derive(Serialize, Deserialize, Debug)]
  5. struct Point {
  6. x: i32,
  7. y: i32,
  8. }
  9.  
  10. fn main() {
  11. let point = Point { x: 1, y: 2 };
  12.  
  13. // Convert the Point to a JSON string.
  14. let serialized = serde_json::to_string(&point).unwrap();
  15.  
  16. // Prints serialized = {"x":1,"y":2}
  17. println!("serialized = {}", serialized);
  18.  
  19. // Convert the JSON string back to a Point.
  20. let deserialized: Point = serde_json::from_str(&serialized).unwrap();
  21.  
  22. // Prints deserialized = Point { x: 1, y: 2 }
  23. println!("deserialized = {:?}", deserialized);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement