Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
// 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