SHARE
TWEET

Untitled

a guest Aug 24th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use serde::{Deserialize, Serialize};
  2.  
  3. #[derive(Serialize, Deserialize)]
  4. struct Eg {
  5.     a: bool,
  6.    
  7.     #[serde(flatten)]
  8.     params: IndexOrKey
  9.    
  10. }
  11.  
  12. #[derive(Serialize, Deserialize)]
  13. enum IndexOrKey {
  14.     #[serde(rename = "key_based")]
  15.     Key(bool),
  16.     Index(bool)
  17. }
  18.  
  19.  
  20. fn main() {
  21.     let a = Eg {
  22.         a: true,
  23.         params: IndexOrKey::Key(true)
  24.     };
  25.    
  26.     let j = serde_json::to_string(&a).expect("Ok");
  27.     dbg!(&j);
  28. }
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