Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created August 24, 2012 18:01
Show Gist options
  • Save nikomatsakis/3453588 to your computer and use it in GitHub Desktop.
Save nikomatsakis/3453588 to your computer and use it in GitHub Desktop.
struct dtor {
x: @mut int;
drop {
// abuse access to shared mutable state to write this code
*self.x -= 1;
}
}
fn unwrap<T>(+o: option<T>) -> T {
match move o {
some(move v) => v,
none => fail
}
}
fn main() {
let x = @mut 1;
{
let b = some(dtor { x:x });
let c = unwrap(b);
}
assert *x == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment