use clone::Clone;
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
+use convert::From;
use default::Default;
use fmt::{self, Debug, Display};
use marker::{Copy, PhantomData, Send, Sync, Sized, Unsize};
/// ```
#[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
}
}
+#[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)
+ }
+}
+
+#[unstable(feature = "coerce_unsized", issue = "27732")]
+impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
+
/// A mutable memory location with dynamically checked borrow rules
///
/// See the [module-level documentation](index.html) for more.
/// ```
#[inline]
#[unstable(feature = "as_unsafe_cell", issue = "27708")]
+ #[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")]
pub unsafe fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
&self.value
}
+ /// Returns a raw pointer to the underlying data in this cell.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::cell::RefCell;
+ ///
+ /// let c = RefCell::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 `RefCell` mutably (at compile-time) so there is no
}
}
+#[stable(feature = "cell_from", since = "1.12.0")]
+impl<T> From<T> for RefCell<T> {
+ fn from(t: T) -> RefCell<T> {
+ RefCell::new(t)
+ }
+}
+
+#[unstable(feature = "coerce_unsized", issue = "27732")]
+impl<T: CoerceUnsized<U>, U> CoerceUnsized<RefCell<U>> for RefCell<T> {}
+
struct BorrowRef<'b> {
borrow: &'b Cell<BorrowFlag>,
}
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)
+ }
+}
+
+#[unstable(feature = "coerce_unsized", issue = "27732")]
+impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
+
+#[allow(unused)]
+fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) {
+ let _: UnsafeCell<&Send> = a;
+ let _: Cell<&Send> = b;
+ let _: RefCell<&Send> = c;
+}