diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 4cb2c792194..24e7decfb82 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -21,6 +21,7 @@ use unstable::intrinsics::transmute; use ops::Drop; use kinds::{Freeze, Send}; use clone::{Clone, DeepClone}; +use mutable::Mut; struct RcBox { value: T, @@ -54,6 +55,16 @@ impl Rc { } } +impl Rc> { + /// Construct a new reference-counted box from a `Mut`-wrapped `Freeze` value + #[inline] + pub fn from_mut(value: Mut) -> Rc> { + unsafe { + Rc::new_unchecked(value) + } + } +} + impl Rc { /// Unsafety construct a new reference-counted box from any value. /// @@ -146,4 +157,10 @@ mod test_rc { let x = Rc::from_send(~5); assert_eq!(**x.borrow(), 5); } + + #[test] + fn test_from_mut() { + let a = 10; + let _x = Rc::from_mut(Mut::new(&a)); + } }