Skip to content
Closed
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
51a2e2f
Allow more Cell methods for non-Copy types
RalfJung Feb 13, 2017
044ed10
Remove Copy bound from some Cell trait impls
RalfJung Feb 14, 2017
ca54fc7
Show five traits implementation in help when there are exactly five
seppo0010 Feb 14, 2017
b2c4e74
rustc: Link statically to the MSVCRT
alexcrichton Feb 14, 2017
aebd94f
Stabilize field init shorthand
est31 Feb 12, 2017
5156ded
make doc consistent with var name
king6cong Feb 15, 2017
938fed7
Update procedural-macros.md
DaseinPhaos Feb 15, 2017
b821313
sys/mod doc update and mod import order adjust
king6cong Feb 15, 2017
577497b
Fix typo
comonadd Feb 15, 2017
b6a1618
book: don’t use GNU extensions in the example unnecessarily
mina86 Feb 13, 2017
cf20d8e
static recursion test added to compile-fail test suite
cseale Feb 15, 2017
d5a4db3
Fix parameter to GetUserProfileDirectoryW
retep998 Feb 15, 2017
e77f856
Add a test that -fPIC is applied
brson Feb 14, 2017
7a028e5
Rollup merge of #39761 - est31:master, r=aturon
frewsxcv Feb 16, 2017
016f73b
Rollup merge of #39775 - mina86:master, r=steveklabnik
frewsxcv Feb 16, 2017
54d75ac
Rollup merge of #39793 - RalfJung:cell, r=alexcrichton
frewsxcv Feb 16, 2017
10d2f6c
Rollup merge of #39803 - brson:fpic, r=alexcrichton
frewsxcv Feb 16, 2017
4f8d4be
Rollup merge of #39804 - seppo0010:recommend-five-traits, r=jonathand…
frewsxcv Feb 16, 2017
bf5604c
Rollup merge of #39834 - cseale:feature-gate-static-recursion, r=est31
frewsxcv Feb 16, 2017
e359698
Rollup merge of #39837 - alexcrichton:llvm-crt-static, r=brson
frewsxcv Feb 16, 2017
c6bdab9
Rollup merge of #39839 - king6cong:refine-doc, r=frewsxcv
frewsxcv Feb 16, 2017
1b28c13
Rollup merge of #39840 - DaseinPhaos:patch-2, r=frewsxcv
frewsxcv Feb 16, 2017
047e310
Rollup merge of #39844 - king6cong:sys, r=alexcrichton
frewsxcv Feb 16, 2017
034acc1
Rollup merge of #39846 - WRONGWAY4YOU:typo-fix, r=frewsxcv
frewsxcv Feb 16, 2017
6343542
Rollup merge of #39861 - retep998:small-fix, r=alexcrichton
frewsxcv Feb 16, 2017
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
124 changes: 62 additions & 62 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,66 +213,6 @@ impl<T:Copy> Cell<T> {
pub fn get(&self) -> T {
unsafe{ *self.value.get() }
}

/// Returns a reference to the underlying `UnsafeCell`.
///
/// # Examples
///
/// ```
/// #![feature(as_unsafe_cell)]
///
/// use std::cell::Cell;
///
/// let c = Cell::new(5);
///
/// let uc = c.as_unsafe_cell();
/// ```
#[inline]
#[unstable(feature = "as_unsafe_cell", issue = "27708")]
#[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")]
pub fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
&self.value
}

/// Returns a raw pointer to the underlying data in this cell.
///
/// # Examples
///
/// ```
/// use std::cell::Cell;
///
/// let c = Cell::new(5);
///
/// let ptr = c.as_ptr();
/// ```
#[inline]
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
pub fn as_ptr(&self) -> *mut T {
self.value.get()
}

/// Returns a mutable reference to the underlying data.
///
/// This call borrows `Cell` mutably (at compile-time) which guarantees
/// that we possess the only reference.
///
/// # Examples
///
/// ```
/// use std::cell::Cell;
///
/// let mut c = Cell::new(5);
/// *c.get_mut() += 1;
///
/// assert_eq!(c.get(), 6);
/// ```
#[inline]
#[stable(feature = "cell_get_mut", since = "1.11.0")]
pub fn get_mut(&mut self) -> &mut T {
unsafe {
&mut *self.value.get()
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -290,7 +230,7 @@ impl<T:Copy> Clone for Cell<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Default + Copy> Default for Cell<T> {
impl<T:Default> Default for Cell<T> {
/// Creates a `Cell<T>`, with the `Default` value for T.
#[inline]
fn default() -> Cell<T> {
Expand Down Expand Up @@ -346,7 +286,7 @@ impl<T:Ord + Copy> Ord for Cell<T> {
}

#[stable(feature = "cell_from", since = "1.12.0")]
impl<T: Copy> From<T> for Cell<T> {
impl<T> From<T> for Cell<T> {
fn from(t: T) -> Cell<T> {
Cell::new(t)
}
Expand All @@ -370,6 +310,66 @@ impl<T> Cell<T> {
}
}

/// Returns a reference to the underlying `UnsafeCell`.
///
/// # Examples
///
/// ```
/// #![feature(as_unsafe_cell)]
///
/// use std::cell::Cell;
///
/// let c = Cell::new(5);
///
/// let uc = c.as_unsafe_cell();
/// ```
#[inline]
#[unstable(feature = "as_unsafe_cell", issue = "27708")]
#[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")]
pub fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
&self.value
}

/// Returns a raw pointer to the underlying data in this cell.
///
/// # Examples
///
/// ```
/// use std::cell::Cell;
///
/// let c = Cell::new(5);
///
/// let ptr = c.as_ptr();
/// ```
#[inline]
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
pub fn as_ptr(&self) -> *mut T {
self.value.get()
}

/// Returns a mutable reference to the underlying data.
///
/// This call borrows `Cell` mutably (at compile-time) which guarantees
/// that we possess the only reference.
///
/// # Examples
///
/// ```
/// use std::cell::Cell;
///
/// let mut c = Cell::new(5);
/// *c.get_mut() += 1;
///
/// assert_eq!(c.get(), 6);
/// ```
#[inline]
#[stable(feature = "cell_get_mut", since = "1.11.0")]
pub fn get_mut(&mut self) -> &mut T {
unsafe {
&mut *self.value.get()
}
}

/// Sets the contained value.
///
/// # Examples
Expand Down