Created
November 22, 2013 09:24
-
-
Save derekchiang/7597202 to your computer and use it in GitHub Desktop.
It's amazing how hard it is to get code to compile in Rust. This is the result of an hour-long struggle. It demonstrates one usage of `extra::json`. Hope it helps someone.
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
// Compile with rustc 0.9-pre (727b70d 2013-11-17 21:11:24 -0800) | |
#[feature(managed_boxes)]; | |
extern mod extra; | |
use extra::json; | |
use std::io::stdio; | |
use extra::serialize::Encodable; | |
#[deriving(Encodable, Decodable)] | |
struct Person { | |
name: ~str, | |
height: f64, | |
age: int, | |
} | |
fn main() { | |
let out = @mut stdio::stdout(); | |
let encoder = &mut json::Encoder((out as @mut std::io::Writer)); | |
let p = &Person{ | |
name: ~"Derek", | |
height: 173.5, | |
age: 20, | |
}; | |
p.encode(encoder); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment