From e0ede9c6b3894851b800a323757857eba07943b5 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 10 Jul 2014 14:19:17 -0700 Subject: Stabilization for `owned` (now `boxed`) and `cell` This PR is the outcome of the library stabilization meeting for the `liballoc::owned` and `libcore::cell` modules. Aside from the stability attributes, there are a few breaking changes: * The `owned` modules is now named `boxed`, to better represent its contents. (`box` was unavailable, since it's a keyword.) This will help avoid the misconception that `Box` plays a special role wrt ownership. * The `AnyOwnExt` extension trait is renamed to `BoxAny`, and its `move` method is renamed to `downcast`, in both cases to improve clarity. * The recently-added `AnySendOwnExt` extension trait is removed; it was not being used and is unnecessary. [breaking-change] --- src/libcore/cell.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 355ee7c7a16..51b5d0aded8 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -163,11 +163,13 @@ use option::{None, Option, Some}; use ty::Unsafe; /// A mutable memory location that admits only `Copy` data. +#[unstable = "likely to be renamed; otherwise stable"] pub struct Cell { value: Unsafe, noshare: marker::NoShare, } +#[stable] impl Cell { /// Creates a new `Cell` containing the given value. pub fn new(value: T) -> Cell { @@ -192,13 +194,14 @@ impl Cell { } } -#[unstable] +#[unstable = "waiting for `Clone` trait to become stable"] impl Clone for Cell { fn clone(&self) -> Cell { Cell::new(self.get()) } } +#[unstable = "waiting for `PartialEq` trait to become stable"] impl PartialEq for Cell { fn eq(&self, other: &Cell) -> bool { self.get() == other.get() @@ -206,6 +209,7 @@ impl PartialEq for Cell { } /// A mutable memory location with dynamically checked borrow rules +#[unstable = "likely to be renamed; otherwise stable"] pub struct RefCell { value: Unsafe, borrow: Cell, @@ -221,6 +225,7 @@ static WRITING: BorrowFlag = -1; impl RefCell { /// Create a new `RefCell` containing `value` + #[stable] pub fn new(value: T) -> RefCell { RefCell { value: Unsafe::new(value), @@ -231,6 +236,7 @@ impl RefCell { } /// Consumes the `RefCell`, returning the wrapped value. + #[unstable = "may be renamed, depending on global conventions"] pub fn unwrap(self) -> T { debug_assert!(self.borrow.get() == UNUSED); unsafe{self.value.unwrap()} @@ -242,6 +248,7 @@ impl RefCell { /// immutable borrows can be taken out at the same time. /// /// Returns `None` if the value is currently mutably borrowed. + #[unstable = "may be renamed, depending on global conventions"] pub fn try_borrow<'a>(&'a self) -> Option> { match self.borrow.get() { WRITING => None, @@ -260,6 +267,7 @@ impl RefCell { /// # Failure /// /// Fails if the value is currently mutably borrowed. + #[unstable] pub fn borrow<'a>(&'a self) -> Ref<'a, T> { match self.try_borrow() { Some(ptr) => ptr, @@ -273,6 +281,7 @@ impl RefCell { /// cannot be borrowed while this borrow is active. /// /// Returns `None` if the value is currently borrowed. + #[unstable = "may be renamed, depending on global conventions"] pub fn try_borrow_mut<'a>(&'a self) -> Option> { match self.borrow.get() { UNUSED => { @@ -291,6 +300,7 @@ impl RefCell { /// # Failure /// /// Fails if the value is currently borrowed. + #[unstable] pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> { match self.try_borrow_mut() { Some(ptr) => ptr, @@ -299,13 +309,14 @@ impl RefCell { } } -#[unstable] +#[unstable = "waiting for `Clone` to become stable"] impl Clone for RefCell { fn clone(&self) -> RefCell { RefCell::new(self.borrow().clone()) } } +#[unstable = "waiting for `PartialEq` to become stable"] impl PartialEq for RefCell { fn eq(&self, other: &RefCell) -> bool { *self.borrow() == *other.borrow() @@ -313,6 +324,7 @@ impl PartialEq for RefCell { } /// Wraps a borrowed reference to a value in a `RefCell` box. +#[unstable] pub struct Ref<'b, T> { // FIXME #12808: strange name to try to avoid interfering with // field accesses of the contained type via Deref @@ -320,6 +332,7 @@ pub struct Ref<'b, T> { } #[unsafe_destructor] +#[unstable] impl<'b, T> Drop for Ref<'b, T> { fn drop(&mut self) { let borrow = self._parent.borrow.get(); @@ -328,6 +341,7 @@ impl<'b, T> Drop for Ref<'b, T> { } } +#[unstable = "waiting for `Deref` to become stable"] impl<'b, T> Deref for Ref<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { @@ -341,7 +355,7 @@ impl<'b, T> Deref for Ref<'b, T> { /// /// A `Clone` implementation would interfere with the widespread /// use of `r.borrow().clone()` to clone the contents of a `RefCell`. -#[experimental] +#[experimental = "likely to be moved to a method, pending language changes"] pub fn clone_ref<'b, T>(orig: &Ref<'b, T>) -> Ref<'b, T> { // Since this Ref exists, we know the borrow flag // is not set to WRITING. @@ -355,6 +369,7 @@ pub fn clone_ref<'b, T>(orig: &Ref<'b, T>) -> Ref<'b, T> { } /// Wraps a mutable borrowed reference to a value in a `RefCell` box. +#[unstable] pub struct RefMut<'b, T> { // FIXME #12808: strange name to try to avoid interfering with // field accesses of the contained type via Deref @@ -362,6 +377,7 @@ pub struct RefMut<'b, T> { } #[unsafe_destructor] +#[unstable] impl<'b, T> Drop for RefMut<'b, T> { fn drop(&mut self) { let borrow = self._parent.borrow.get(); @@ -370,6 +386,7 @@ impl<'b, T> Drop for RefMut<'b, T> { } } +#[unstable = "waiting for `Deref` to become stable"] impl<'b, T> Deref for RefMut<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { @@ -377,6 +394,7 @@ impl<'b, T> Deref for RefMut<'b, T> { } } +#[unstable = "waiting for `DerefMut` to become stable"] impl<'b, T> DerefMut for RefMut<'b, T> { #[inline] fn deref_mut<'a>(&'a mut self) -> &'a mut T { -- cgit 1.4.1-3-g733a5