}
}
+impl<T, const N: usize> Cell<[T; N]> {
+ /// Returns a `&[Cell<T>; N]` from a `&Cell<[T; N]>`
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(as_array_of_cells)]
+ /// use std::cell::Cell;
+ ///
+ /// let mut array: [i32; 3] = [1, 2, 3];
+ /// let cell_array: &Cell<[i32; 3]> = Cell::from_mut(&mut array);
+ /// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
+ /// ```
+ #[unstable(feature = "as_array_of_cells", issue = "88248")]
+ pub fn as_array_of_cells(&self) -> &[Cell<T>; N] {
+ // SAFETY: `Cell<T>` has the same memory layout as `T`.
+ unsafe { &*(self as *const Cell<[T; N]> as *const [Cell<T>; N]) }
+ }
+}
+
/// A mutable memory location with dynamically checked borrow rules
///
/// See the [module-level documentation](self) for more.
pub struct RefCell<T: ?Sized> {
borrow: Cell<BorrowFlag>,
// Stores the location of the earliest currently active borrow.
- // This gets updated whenver we go from having zero borrows
+ // This gets updated whenever we go from having zero borrows
// to having a single borrow. When a borrow occurs, this gets included
// in the generated `BorrowError/`BorrowMutError`
#[cfg(feature = "debug_refcell")]
}
/// Gets a mutable pointer to the wrapped value.
- /// The difference to [`get`] is that this function accepts a raw pointer,
+ /// The difference from [`get`] is that this function accepts a raw pointer,
/// which is useful to avoid the creation of temporary references.
///
/// The result can be cast to a pointer of any kind.
/// calling `get` would require creating a reference to uninitialized data:
///
/// ```
- /// #![feature(unsafe_cell_raw_get)]
/// use std::cell::UnsafeCell;
/// use std::mem::MaybeUninit;
///
/// assert_eq!(uc.into_inner(), 5);
/// ```
#[inline(always)]
- #[unstable(feature = "unsafe_cell_raw_get", issue = "66358")]
+ #[stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
pub const fn raw_get(this: *const Self) -> *mut T {
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
// #[repr(transparent)]. This exploits libstd's special status, there is