Rollup merge of #35392 - malbarbo:cell-from, r=brson
Implement From for Cell, RefCell and UnsafeCell Considering that `From` is implemented for `Box`, `Rc` and `Arc`, it seems [reasonable](https://internals.rust-lang.org/t/implementing-from-t-for-other-std-types/3744) to implement it for `Cell`, `RefCell` and `UnsafeCell`.
This commit is contained in:
commit
fa57f358a3
@ -146,6 +146,7 @@
|
||||
|
||||
use clone::Clone;
|
||||
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
|
||||
use convert::From;
|
||||
use default::Default;
|
||||
use fmt::{self, Debug, Display};
|
||||
use marker::{Copy, PhantomData, Send, Sync, Sized, Unsize};
|
||||
@ -329,6 +330,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.
|
||||
@ -742,6 +750,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>,
|
||||
}
|
||||
@ -1064,3 +1079,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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user