Skip to content

Instantly share code, notes, and snippets.

@krdln
Created January 5, 2014 18:07
Show Gist options
  • Save krdln/8271696 to your computer and use it in GitHub Desktop.
Save krdln/8271696 to your computer and use it in GitHub Desktop.
enum List_ {
Cons(int, ~List_),
Nil
}
struct List(~List_);
impl List {
fn prepend(&mut self, x : int) {
let List(old) = self; // I have no idea, how to write this line
*self = List(~Cons(x, old));
}
}
fn main() {
let mut li = List(~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