diff options
| author | Steven Fackler <sfackler@gmail.com> | 2013-11-16 21:59:42 -0800 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2013-11-22 21:19:53 -0800 |
| commit | c6ca9abcc651423fe85f522cbd20f1e64463c36f (patch) | |
| tree | 702135483472a595dc97949444ffc0b43114b36a /src/libstd | |
| parent | 48cd8c646ace585153d6ed25baccdd8420742e42 (diff) | |
| download | rust-c6ca9abcc651423fe85f522cbd20f1e64463c36f.tar.gz rust-c6ca9abcc651423fe85f522cbd20f1e64463c36f.zip | |
Add Rc::from_mut
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rc.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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<T> { value: T, @@ -54,6 +55,16 @@ impl<T: Send> Rc<T> { } } +impl<T: Freeze> Rc<Mut<T>> { + /// Construct a new reference-counted box from a `Mut`-wrapped `Freeze` value + #[inline] + pub fn from_mut(value: Mut<T>) -> Rc<Mut<T>> { + unsafe { + Rc::new_unchecked(value) + } + } +} + impl<T> Rc<T> { /// 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)); + } } |
