diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index d130b0279a2..736797d162b 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -213,6 +213,102 @@ impl Cell { pub fn get(&self) -> T { unsafe{ *self.value.get() } } +} + +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl Send for Cell where T: Send {} + +#[stable(feature = "rust1", since = "1.0.0")] +impl !Sync for Cell {} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Clone for Cell { + #[inline] + fn clone(&self) -> Cell { + Cell::new(self.get()) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Default for Cell { + /// Creates a `Cell`, with the `Default` value for T. + #[inline] + fn default() -> Cell { + Cell::new(Default::default()) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl PartialEq for Cell { + #[inline] + fn eq(&self, other: &Cell) -> bool { + self.get() == other.get() + } +} + +#[stable(feature = "cell_eq", since = "1.2.0")] +impl Eq for Cell {} + +#[stable(feature = "cell_ord", since = "1.10.0")] +impl PartialOrd for Cell { + #[inline] + fn partial_cmp(&self, other: &Cell) -> Option { + self.get().partial_cmp(&other.get()) + } + + #[inline] + fn lt(&self, other: &Cell) -> bool { + self.get() < other.get() + } + + #[inline] + fn le(&self, other: &Cell) -> bool { + self.get() <= other.get() + } + + #[inline] + fn gt(&self, other: &Cell) -> bool { + self.get() > other.get() + } + + #[inline] + fn ge(&self, other: &Cell) -> bool { + self.get() >= other.get() + } +} + +#[stable(feature = "cell_ord", since = "1.10.0")] +impl Ord for Cell { + #[inline] + fn cmp(&self, other: &Cell) -> Ordering { + self.get().cmp(&other.get()) + } +} + +#[stable(feature = "cell_from", since = "1.12.0")] +impl From for Cell { + fn from(t: T) -> Cell { + Cell::new(t) + } +} + +impl Cell { + /// Creates a new `Cell` containing the given value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// ``` + #[stable(feature = "rust1", since = "1.0.0")] + #[inline] + pub const fn new(value: T) -> Cell { + Cell { + value: UnsafeCell::new(value), + } + } /// Returns a reference to the underlying `UnsafeCell`. /// @@ -273,102 +369,6 @@ impl Cell { &mut *self.value.get() } } -} - -#[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send for Cell where T: Send {} - -#[stable(feature = "rust1", since = "1.0.0")] -impl !Sync for Cell {} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Cell { - #[inline] - fn clone(&self) -> Cell { - Cell::new(self.get()) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Default for Cell { - /// Creates a `Cell`, with the `Default` value for T. - #[inline] - fn default() -> Cell { - Cell::new(Default::default()) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for Cell { - #[inline] - fn eq(&self, other: &Cell) -> bool { - self.get() == other.get() - } -} - -#[stable(feature = "cell_eq", since = "1.2.0")] -impl Eq for Cell {} - -#[stable(feature = "cell_ord", since = "1.10.0")] -impl PartialOrd for Cell { - #[inline] - fn partial_cmp(&self, other: &Cell) -> Option { - self.get().partial_cmp(&other.get()) - } - - #[inline] - fn lt(&self, other: &Cell) -> bool { - self.get() < other.get() - } - - #[inline] - fn le(&self, other: &Cell) -> bool { - self.get() <= other.get() - } - - #[inline] - fn gt(&self, other: &Cell) -> bool { - self.get() > other.get() - } - - #[inline] - fn ge(&self, other: &Cell) -> bool { - self.get() >= other.get() - } -} - -#[stable(feature = "cell_ord", since = "1.10.0")] -impl Ord for Cell { - #[inline] - fn cmp(&self, other: &Cell) -> Ordering { - self.get().cmp(&other.get()) - } -} - -#[stable(feature = "cell_from", since = "1.12.0")] -impl From for Cell { - fn from(t: T) -> Cell { - Cell::new(t) - } -} - -impl Cell { - /// Creates a new `Cell` containing the given value. - /// - /// # Examples - /// - /// ``` - /// use std::cell::Cell; - /// - /// let c = Cell::new(5); - /// ``` - #[stable(feature = "rust1", since = "1.0.0")] - #[inline] - pub const fn new(value: T) -> Cell { - Cell { - value: UnsafeCell::new(value), - } - } /// Sets the contained value. ///