#[repr(transparent)]pub struct CovariantUnsafeCell<T>(UnsafeCell<T>)
where
T: ?Sized;covariant_unsafe_cell #159735)Expand description
Covariant version of UnsafeCell.
Tuple Fields§
§0: UnsafeCell<T>covariant_unsafe_cell #159735)Implementations§
Source§impl<T> CovariantUnsafeCell<T>
impl<T> CovariantUnsafeCell<T>
Sourcepub const fn new(value: T) -> CovariantUnsafeCell<T>
🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)
pub const fn new(value: T) -> CovariantUnsafeCell<T>
covariant_unsafe_cell #159735)Constructs a new instance of CovariantUnsafeCell which will wrap the specified value.
All access to the inner value through &CovariantUnsafeCell<T> requires unsafe code.
§Examples
Sourcepub const fn into_inner(self) -> T
🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)
pub const fn into_inner(self) -> T
covariant_unsafe_cell #159735)Unwraps the value, consuming the cell.
§Examples
Source§impl<T> CovariantUnsafeCell<T>where
T: ?Sized,
impl<T> CovariantUnsafeCell<T>where
T: ?Sized,
Sourcepub const fn get(&self) -> NonNull<T>
🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)
pub const fn get(&self) -> NonNull<T>
covariant_unsafe_cell #159735)Gets a mutable non-null pointer to the wrapped value.
This can be cast to a pointer of any kind. When creating (shared or mutable) references, you
must uphold the aliasing rules; see the UnsafeCell type-level docs for more discussion
and caveats.
§Examples
Sourcepub const fn get_mut(&mut self) -> &mut T
🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)
pub const fn get_mut(&mut self) -> &mut T
covariant_unsafe_cell #159735)Returns a mutable reference to the underlying data.
This call borrows the CovariantUnsafeCell mutably (at compile-time) which guarantees that
we possess the only reference.
§Examples
Sourcepub const fn raw_get(this: *const CovariantUnsafeCell<T>) -> *mut T
🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)
pub const fn raw_get(this: *const CovariantUnsafeCell<T>) -> *mut T
covariant_unsafe_cell #159735)Gets a mutable pointer to the wrapped value.
The difference from get is that this function accepts a raw pointer,
which is useful to avoid the creation of temporary references.
This can be cast to a pointer of any kind. When creating (shared or mutable) references, you
must uphold the aliasing rules; see [the UnsafeCell type-level docs] for more discussion
and caveats.
§Examples
Gradual initialization of an CovariantUnsafeCell requires raw_get, as
calling get would require creating a reference to uninitialized data:
#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;
use std::mem::MaybeUninit;
let m = MaybeUninit::<CovariantUnsafeCell<i32>>::uninit();
unsafe { CovariantUnsafeCell::raw_get(m.as_ptr()).write(5); }
// avoid below which references to uninitialized data
// unsafe { CovariantUnsafeCell::get(&*m.as_ptr()).write(5); }
let uc = unsafe { m.assume_init() };
assert_eq!(uc.into_inner(), 5);Trait Implementations§
impl<T> !Sync for CovariantUnsafeCell<T>where
T: ?Sized,
impl<T, U> CoerceUnsized<CovariantUnsafeCell<U>> for CovariantUnsafeCell<T>where
T: CoerceUnsized<U>,
Auto Trait Implementations§
impl<T> !Freeze for CovariantUnsafeCell<T>
impl<T> !RefUnwindSafe for CovariantUnsafeCell<T>
impl<T> Send for CovariantUnsafeCell<T>
impl<T> Unpin for CovariantUnsafeCell<T>
impl<T> UnsafeUnpin for CovariantUnsafeCell<T>
impl<T> UnwindSafe for CovariantUnsafeCell<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more