Created
April 16, 2016 15:07
-
-
Save polachok/1fd5fb24e051e2217732a4fe63936832 to your computer and use it in GitHub Desktop.
t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rustc_serialize; | |
use rustc_serialize::json; | |
#[derive(RustcDecodable, RustcEncodable, Debug)] | |
enum Message { | |
Type1(String), | |
Type2(u64), | |
} | |
fn main() { | |
let msg1 = Message::Type1("Hello world".to_string()); | |
let msg2 = Message::Type2(5); | |
// Serialize using `json::encode` | |
let encoded = json::encode(&msg1).unwrap(); | |
// Deserialize using `json::decode` | |
let decoded: Message = json::decode(&encoded).unwrap(); | |
println!("encoded: {}, decoded: {:?}", encoded, decoded); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment