rust/src/test/run-pass/resource-destruct.rs
Marijn Haverbeke 9561def209 Use 'resource' rather than 'res' as a keyword
Resources are now defined like...

    resource fd(int n) { close(n); }

Calling fd with an int will then produce a non-copyable value
that, when dropped, will call close on the given int.
2011-06-28 18:00:39 +02:00

17 lines
287 B
Rust

resource shrinky_pointer(@mutable int i) {
*i -= 1;
}
fn look_at(&shrinky_pointer pt) -> int {
ret **pt;
}
fn main() {
auto my_total = @mutable 10;
{
auto pt <- shrinky_pointer(my_total);
assert (look_at(pt) == 10);
}
assert (*my_total == 9);
}