rust/src/test/run-pass/resource-destruct.rs
2012-11-14 19:26:37 -08:00

27 lines
522 B
Rust

struct shrinky_pointer {
i: @@mut int,
}
impl shrinky_pointer : Drop {
fn finalize() {
log(error, ~"Hello!"); **(self.i) -= 1;
}
}
impl shrinky_pointer {
fn look_at() -> int { return **(self.i); }
}
fn shrinky_pointer(i: @@mut int) -> shrinky_pointer {
shrinky_pointer {
i: i
}
}
fn main() {
let my_total = @@mut 10;
{ let pt = move shrinky_pointer(my_total); assert (pt.look_at() == 10); }
log(error, fmt!("my_total = %d", **my_total));
assert (**my_total == 9);
}