From 1403df72c82d3c3c2c19369c5f4bb34b3e095604 Mon Sep 17 00:00:00 2001 From: Marco A L Barbosa Date: Fri, 5 Aug 2016 16:57:19 -0300 Subject: [PATCH] Implement From for Cell, RefCell and UnsafeCell --- src/libcore/cell.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 06af200e47839..eb694319f42ef 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 Ord for Cell { } } +#[stable(feature = "cell_from", since = "1.12.0")] +impl From for Cell { + fn from(t: T) -> Cell { + 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 Ord for RefCell { } } +#[stable(feature = "cell_from", since = "1.12.0")] +impl From for RefCell { + fn from(t: T) -> RefCell { + RefCell::new(t) + } +} + struct BorrowRef<'b> { borrow: &'b Cell, } @@ -957,3 +972,10 @@ impl Default for UnsafeCell { UnsafeCell::new(Default::default()) } } + +#[stable(feature = "cell_from", since = "1.12.0")] +impl From for UnsafeCell { + fn from(t: T) -> UnsafeCell { + UnsafeCell::new(t) + } +}