rust/src/test/run-pass/resource-generic.rs
Tim Chevalier ed357af980 Convert more resource tests to use classes with dtors
And monomorphize dtors correctly.
2012-05-22 22:12:18 -04:00

16 lines
329 B
Rust

class finish<T: copy> {
let arg: {val: T, fin: native fn(T)};
new(arg: {val: T, fin: native fn(T)}) {
self.arg = arg;
}
drop { self.arg.fin(self.arg.val); }
}
fn main() {
let box = @mut 10;
fn dec_box(&&i: @mut int) { *i -= 1; }
{ let _i <- finish({val: box, fin: dec_box}); }
assert (*box == 9);
}