Created
August 24, 2012 18:01
-
-
Save nikomatsakis/3453588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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