]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/resource-destruct.rs
Change finalize -> drop.
[rust.git] / src / test / run-pass / resource-destruct.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 struct shrinky_pointer {
12   i: @@mut int,
13 }
14
15 #[unsafe_destructor]
16 impl Drop for shrinky_pointer {
17     fn drop(&self) {
18         unsafe {
19             error!(~"Hello!"); **(self.i) -= 1;
20         }
21     }
22 }
23
24 impl shrinky_pointer {
25     pub fn look_at(&self) -> int { return **(self.i); }
26 }
27
28 fn shrinky_pointer(i: @@mut int) -> shrinky_pointer {
29     shrinky_pointer {
30         i: i
31     }
32 }
33
34 pub fn main() {
35     let my_total = @@mut 10;
36     { let pt = shrinky_pointer(my_total); assert!((pt.look_at() == 10)); }
37     error!("my_total = %d", **my_total);
38     assert_eq!(**my_total, 9);
39 }