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.
17 lines
287 B
Rust
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);
|
|
}
|