Add Rc::from_mut
This commit is contained in:
parent
48cd8c646a
commit
c6ca9abcc6
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user