SHARE
TWEET

Untitled

a guest Oct 14th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use serde::Serialize;
  2.  
  3. #[derive(Serialize)]
  4. struct MyStruct {
  5.     foo: Result<u32, String>
  6. }
  7.  
  8. fn main() {
  9.     let m = MyStruct {
  10.         foo: Ok(43)
  11.     };
  12.     let n = MyStruct {
  13.         foo: Err("oh no!".into())
  14.     };
  15.    
  16.     // {
  17.     //   "foo": {
  18.     //     "Ok": 43
  19.     //   }
  20.     // }
  21.     println!("{}", serde_json::to_string_pretty(&m).unwrap());
  22.    
  23.     // {
  24.     //   "foo": {
  25.     //     "Err": "oh no!"
  26.     //   }
  27.     // }
  28.     println!("{}", serde_json::to_string_pretty(&n).unwrap());
  29. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top