Skip to content

Instantly share code, notes, and snippets.

@derekchiang
Created November 22, 2013 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekchiang/7597202 to your computer and use it in GitHub Desktop.
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.
// 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