about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMarco A L Barbosa <malbarbo@gmail.com>2016-08-05 16:57:19 -0300
committerMarco A L Barbosa <malbarbo@gmail.com>2016-08-05 16:57:19 -0300
commit1403df72c82d3c3c2c19369c5f4bb34b3e095604 (patch)
tree25ff31d46acd625a57ca700a637b8a2b8c48b44f /src
parent4c02363852e6ce41cf2da1b43a32cb7780a9b067 (diff)
downloadrust-1403df72c82d3c3c2c19369c5f4bb34b3e095604.tar.gz
rust-1403df72c82d3c3c2c19369c5f4bb34b3e095604.zip
Implement From for Cell, RefCell and UnsafeCell
Diffstat (limited to 'src')
-rw-r--r--src/libcore/cell.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 06af200e478..eb694319f42 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -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)
+    }
+}