Skip to content

Commit 7e2fa43

Browse files
authored
Rollup merge of rust-lang#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`.
2 parents ad247ce + 1403df7 commit 7e2fa43

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libcore/cell.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146

147147
use clone::Clone;
148148
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
149+
use convert::From;
149150
use default::Default;
150151
use fmt::{self, Debug, Display};
151152
use marker::{Copy, PhantomData, Send, Sync, Sized, Unsize};
@@ -329,6 +330,13 @@ impl<T:Ord + Copy> Ord for Cell<T> {
329330
}
330331
}
331332

333+
#[stable(feature = "cell_from", since = "1.12.0")]
334+
impl<T: Copy> From<T> for Cell<T> {
335+
fn from(t: T) -> Cell<T> {
336+
Cell::new(t)
337+
}
338+
}
339+
332340
/// A mutable memory location with dynamically checked borrow rules
333341
///
334342
/// See the [module-level documentation](index.html) for more.
@@ -742,6 +750,13 @@ impl<T: ?Sized + Ord> Ord for RefCell<T> {
742750
}
743751
}
744752

753+
#[stable(feature = "cell_from", since = "1.12.0")]
754+
impl<T> From<T> for RefCell<T> {
755+
fn from(t: T) -> RefCell<T> {
756+
RefCell::new(t)
757+
}
758+
}
759+
745760
struct BorrowRef<'b> {
746761
borrow: &'b Cell<BorrowFlag>,
747762
}
@@ -1064,3 +1079,10 @@ impl<T: Default> Default for UnsafeCell<T> {
10641079
UnsafeCell::new(Default::default())
10651080
}
10661081
}
1082+
1083+
#[stable(feature = "cell_from", since = "1.12.0")]
1084+
impl<T> From<T> for UnsafeCell<T> {
1085+
fn from(t: T) -> UnsafeCell<T> {
1086+
UnsafeCell::new(t)
1087+
}
1088+
}

0 commit comments

Comments
 (0)