rust/src/test/run-pass/resource-generic.rs

10 lines
234 B
Rust
Raw Normal View History

resource finish<T>(arg: {val: T, fin: fn(&T) }) { arg.fin(arg.val); }
fn main() {
2011-07-27 14:19:39 +02:00
let box = @mutable 10;
fn dec_box(i: &@mutable int) { *i -= 1; }
2011-07-27 14:19:39 +02:00
{ let i <- finish({val: box, fin: dec_box}); }
assert (*box == 9);
}