Skip to content

Instantly share code, notes, and snippets.

@lilyball
Forked from DaGenix/testmp.rs
Created November 20, 2013 00:33
Show Gist options
  • Select an option

  • Save lilyball/7555278 to your computer and use it in GitHub Desktop.

Select an option

Save lilyball/7555278 to your computer and use it in GitHub Desktop.
enum State {
Even(~int),
Odd(~int)
}
struct MyNumber {
num: State
}
impl MyNumber {
fn new() -> MyNumber {
MyNumber {
num: Even(~0)
}
}
fn next(&mut self) -> bool {
let (next, ret) = match self.num {
Even(ref x) => (Odd(~(**x + 1)), true),
Odd(ref y) => (Even(~(**y + 1)), false)
};
self.num = next;
ret
}
}
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment