37
37
*/
38
38
39
39
use std:: ptr;
40
- use std:: routine:: Runnable ;
41
40
use std:: util;
42
41
43
42
/**
@@ -50,7 +49,7 @@ pub struct CVec<T> {
50
49
}
51
50
52
51
struct DtorRes {
53
- dtor : Option < ~ Runnable > ,
52
+ dtor : Option < proc ( ) > ,
54
53
}
55
54
56
55
#[ unsafe_destructor]
@@ -59,13 +58,13 @@ impl Drop for DtorRes {
59
58
let dtor = util:: replace ( & mut self . dtor , None ) ;
60
59
match dtor {
61
60
None => ( ) ,
62
- Some ( f) => f. run ( )
61
+ Some ( f) => f ( )
63
62
}
64
63
}
65
64
}
66
65
67
66
impl DtorRes {
68
- fn new ( dtor : Option < ~ Runnable > ) -> DtorRes {
67
+ fn new ( dtor : Option < proc ( ) > ) -> DtorRes {
69
68
DtorRes {
70
69
dtor : dtor,
71
70
}
@@ -103,7 +102,7 @@ pub unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
103
102
* * dtor - A function to run when the value is destructed, useful
104
103
* for freeing the buffer, etc.
105
104
*/
106
- pub unsafe fn c_vec_with_dtor < T > ( base : * mut T , len : uint , dtor : ~ Runnable )
105
+ pub unsafe fn c_vec_with_dtor < T > ( base : * mut T , len : uint , dtor : proc ( ) )
107
106
-> CVec < T > {
108
107
return CVec {
109
108
base : base,
@@ -155,19 +154,6 @@ mod tests {
155
154
156
155
use std:: libc:: * ;
157
156
use std:: libc;
158
- use std:: routine:: Runnable ;
159
-
160
- struct LibcFree {
161
- mem : * c_void ,
162
- }
163
-
164
- impl Runnable for LibcFree {
165
- fn run ( ~self ) {
166
- unsafe {
167
- libc:: free ( self . mem )
168
- }
169
- }
170
- }
171
157
172
158
fn malloc ( n : size_t ) -> CVec < u8 > {
173
159
unsafe {
@@ -177,9 +163,7 @@ mod tests {
177
163
178
164
return c_vec_with_dtor ( mem as * mut u8 ,
179
165
n as uint ,
180
- ~LibcFree {
181
- mem : mem,
182
- } as ~Runnable ) ;
166
+ proc ( ) unsafe { libc:: free ( mem) ; } ) ;
183
167
}
184
168
}
185
169
0 commit comments