Implement From for Cell, RefCell and UnsafeCell

This commit is contained in:
Marco A L Barbosa 2016-08-05 16:57:19 -03:00
parent 4c02363852
commit 1403df72c8

View file

@ -146,6 +146,7 @@
use clone::Clone;
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
use convert::From;
use default::Default;
use marker::{Copy, Send, Sync, Sized, Unsize};
use ops::{Deref, DerefMut, Drop, FnOnce, CoerceUnsized};
@ -326,6 +327,13 @@ impl<T:Ord + Copy> Ord for Cell<T> {
}
}
#[stable(feature = "cell_from", since = "1.12.0")]
impl<T: Copy> From<T> for Cell<T> {
fn from(t: T) -> Cell<T> {
Cell::new(t)
}
}
/// A mutable memory location with dynamically checked borrow rules
///
/// See the [module-level documentation](index.html) for more.
@ -635,6 +643,13 @@ impl<T: ?Sized + Ord> Ord for RefCell<T> {
}
}
#[stable(feature = "cell_from", since = "1.12.0")]
impl<T> From<T> for RefCell<T> {
fn from(t: T) -> RefCell<T> {
RefCell::new(t)
}
}
struct BorrowRef<'b> {
borrow: &'b Cell<BorrowFlag>,
}
@ -957,3 +972,10 @@ impl<T: Default> Default for UnsafeCell<T> {
UnsafeCell::new(Default::default())
}
}
#[stable(feature = "cell_from", since = "1.12.0")]
impl<T> From<T> for UnsafeCell<T> {
fn from(t: T) -> UnsafeCell<T> {
UnsafeCell::new(t)
}
}