Skip to content

Instantly share code, notes, and snippets.

@sfackler
Forked from krdln/gist:8271696
Last active January 2, 2016 07:39
Show Gist options
  • Save sfackler/8271819 to your computer and use it in GitHub Desktop.
Save sfackler/8271819 to your computer and use it in GitHub Desktop.
use std::util;
enum List {
Cons(int, ~List),
Nil
}
impl List {
fn prepend(&mut self, x : int) {
let new = ~util::replace(self, Nil);
*self = Cons(x, new);
}
}
fn main() {
let mut li = Cons(2, ~Nil);
li.prepend(1);
println!("{:?}", li);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment