File tree 1 file changed +17
-0
lines changed 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ use unstable::intrinsics::transmute;
21
21
use ops:: Drop ;
22
22
use kinds:: { Freeze , Send } ;
23
23
use clone:: { Clone , DeepClone } ;
24
+ use mutable:: Mut ;
24
25
25
26
struct RcBox < T > {
26
27
value : T ,
@@ -54,6 +55,16 @@ impl<T: Send> Rc<T> {
54
55
}
55
56
}
56
57
58
+ impl < T : Freeze > Rc < Mut < T > > {
59
+ /// Construct a new reference-counted box from a `Mut`-wrapped `Freeze` value
60
+ #[ inline]
61
+ pub fn from_mut ( value : Mut < T > ) -> Rc < Mut < T > > {
62
+ unsafe {
63
+ Rc :: new_unchecked ( value)
64
+ }
65
+ }
66
+ }
67
+
57
68
impl < T > Rc < T > {
58
69
/// Unsafety construct a new reference-counted box from any value.
59
70
///
@@ -146,4 +157,10 @@ mod test_rc {
146
157
let x = Rc :: from_send ( ~5 ) ;
147
158
assert_eq ! ( * * x. borrow( ) , 5 ) ;
148
159
}
160
+
161
+ #[ test]
162
+ fn test_from_mut ( ) {
163
+ let a = 10 ;
164
+ let _x = Rc :: from_mut ( Mut :: new ( & a) ) ;
165
+ }
149
166
}
You can’t perform that action at this time.
0 commit comments