Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement From for Cell, RefCell and UnsafeCell #35392

Merged
merged 1 commit into from
Aug 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>,
}
Expand Down Expand Up @@ -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)
}
}