Skip to content

Commit c6ca9ab

Browse files
committed
Add Rc::from_mut
1 parent 48cd8c6 commit c6ca9ab

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libstd/rc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use unstable::intrinsics::transmute;
2121
use ops::Drop;
2222
use kinds::{Freeze, Send};
2323
use clone::{Clone, DeepClone};
24+
use mutable::Mut;
2425

2526
struct RcBox<T> {
2627
value: T,
@@ -54,6 +55,16 @@ impl<T: Send> Rc<T> {
5455
}
5556
}
5657

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+
5768
impl<T> Rc<T> {
5869
/// Unsafety construct a new reference-counted box from any value.
5970
///
@@ -146,4 +157,10 @@ mod test_rc {
146157
let x = Rc::from_send(~5);
147158
assert_eq!(**x.borrow(), 5);
148159
}
160+
161+
#[test]
162+
fn test_from_mut() {
163+
let a = 10;
164+
let _x = Rc::from_mut(Mut::new(&a));
165+
}
149166
}

0 commit comments

Comments
 (0)