daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top