File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ use core::option::Option;
22
22
use core:: raw:: TraitObject ;
23
23
use core:: result:: Result ;
24
24
use core:: result:: Result :: { Ok , Err } ;
25
+ use core:: ops:: { Deref , DerefMut } ;
25
26
26
27
/// A value that represents the global exchange heap. This is the default
27
28
/// place that the `box` keyword allocates into when no place is supplied.
@@ -147,6 +148,14 @@ impl fmt::Show for Box<Any+'static> {
147
148
}
148
149
}
149
150
151
+ impl < Sized ? T > Deref < T > for Box < T > {
152
+ fn deref ( & self ) -> & T { & * * self }
153
+ }
154
+
155
+ impl < Sized ? T > DerefMut < T > for Box < T > {
156
+ fn deref_mut ( & mut self ) -> & mut T { & mut * * self }
157
+ }
158
+
150
159
#[ cfg( test) ]
151
160
mod test {
152
161
#[ test]
@@ -193,4 +202,10 @@ mod test {
193
202
let s = format ! ( "{}" , b) ;
194
203
assert_eq ! ( s, "&Any" ) ;
195
204
}
205
+
206
+ #[ test]
207
+ fn deref ( ) {
208
+ fn homura < T : Deref < i32 > > ( _: T ) { }
209
+ homura ( box 765i32 ) ;
210
+ }
196
211
}
You can’t perform that action at this time.
0 commit comments