Skip to content

Instantly share code, notes, and snippets.

@Blei
Created December 4, 2013 13:23
Show Gist options
  • Save Blei/7787352 to your computer and use it in GitHub Desktop.
Save Blei/7787352 to your computer and use it in GitHub Desktop.
wtf, rust?
// Config.rs:34
fn save_PrettyJSON<'a, T: Encodable<json::PrettyEncoder<'a>>>(p: &Path, toEncode: ~[T]) {
match File::create(p) {
Some(f) => {
let f2 = @mut f as @mut io::Writer;
let a = &mut json::PrettyEncoder::init(f2);
toEncode.encode(a);
}, None => fail!("failed to save json")
};
}
@Blei
Copy link
Author

Blei commented Dec 4, 2013

#[feature(managed_boxes)];

struct Whatever<'a> { w: &'a mut std::io::Writer }
impl <'a> Whatever<'a> {
    fn new<'b>(w: &'b mut std::io::Writer) -> Whatever<'b> {
        Whatever { w: w }
    }
}

fn save_PrettyJSON(p: &Path) {
    match std::io::File::create(p) {
        Some(f) => {
            let mut f2 = f;
            let a = &mut Whatever::new(@mut f2 as @mut std::io::Writer);
        },
        None => fail!()
    };
}

fn main() {
    save_PrettyJSON(&Path::init("sntahoeu"));
}

@Blei
Copy link
Author

Blei commented Dec 4, 2013

#[feature(managed_boxes)];

struct DroppableStruct;
impl Drop for DroppableStruct {
    fn drop(&mut self) {
        println!("Dropping");
    }
}

trait MyTrait { }
impl MyTrait for DroppableStruct {}


struct Whatever<'a> { w: &'a mut MyTrait }
impl <'a> Whatever<'a> {
    fn new<'b>(w: &'b mut MyTrait) -> Whatever<'b> {
        Whatever { w: w }
    }
}

fn main() {
    let mut f = DroppableStruct;
    let _a = &mut Whatever::new(@mut f as @mut MyTrait);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment