Struct CovariantUnsafeCell
#[repr(transparent)]
pub struct CovariantUnsafeCell<T: ?Sized>(pub(in ::cell::covariant_unsafe_cell) UnsafeCell<T>);
Covariant version of UnsafeCell.
Fields
0: UnsafeCell<T>
Implementations
impl<T> CovariantUnsafeCell<T>
const fn new(value: T) -> CovariantUnsafeCell<T>Constructs a new instance of
CovariantUnsafeCellwhich will wrap the specified value.All access to the inner value through
&CovariantUnsafeCell<T>requiresunsafecode.Examples
use CovariantUnsafeCell; let uc = new;const fn into_inner(self) -> TUnwraps the value, consuming the cell.
Examples
use CovariantUnsafeCell; let uc = new; let five = uc.into_inner;
impl<T: ?Sized> CovariantUnsafeCell<T>
const fn get(&self) -> NonNull<T>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
UnsafeCelltype-level docs for more discussion and caveats.Examples
use CovariantUnsafeCell; use NonNull; let uc = new; let ptr: = uc.get;const fn get_mut(&mut self) -> &mut TReturns a mutable reference to the underlying data.
This call borrows the
CovariantUnsafeCellmutably (at compile-time) which guarantees that we possess the only reference.Examples
use CovariantUnsafeCell; let mut c = new; *c.get_mut += 1; assert_eq!;const fn raw_get(this: *const Self) -> *mut TGets a mutable pointer to the wrapped value. The difference from
getis 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
UnsafeCelltype-level docs] for more discussion and caveats.Examples
Gradual initialization of an
CovariantUnsafeCellrequiresraw_get, as callinggetwould require creating a reference to uninitialized data:use CovariantUnsafeCell; use MaybeUninit; let m = uninit; unsafe // avoid below which references to uninitialized data // unsafe { CovariantUnsafeCell::get(&*m.as_ptr()).write(5); } let uc = unsafe ; assert_eq!;
Trait Implementations
impl<T: ?Sized> !Sync for CovariantUnsafeCell<T>
impl<T: ?Sized> Debug for CovariantUnsafeCell<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T: CoerceUnsized<U>, U> CoerceUnsized<CovariantUnsafeCell<U>> for CovariantUnsafeCell<T>
Auto Trait Implementations
impl<T> !Freeze for CovariantUnsafeCell<T>
impl<T> !RefUnwindSafe for CovariantUnsafeCell<T>
impl<T> Send for CovariantUnsafeCell<T>
where
UnsafeCell<T>: Send,
T: ?Sized,
impl<T> Unpin for CovariantUnsafeCell<T>
where
UnsafeCell<T>: Unpin,
T: ?Sized,
impl<T> UnsafeUnpin for CovariantUnsafeCell<T>
where
UnsafeCell<T>: UnsafeUnpin,
T: ?Sized,
impl<T> UnwindSafe for CovariantUnsafeCell<T>
where
UnsafeCell<T>: UnwindSafe,
T: ?Sized,
Blanket Implementations
impl<T> Any for CovariantUnsafeCell<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for CovariantUnsafeCell<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for CovariantUnsafeCell<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for CovariantUnsafeCell<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for CovariantUnsafeCell<T>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for CovariantUnsafeCell<T>
impl<T, U> Into<U> for CovariantUnsafeCell<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for CovariantUnsafeCell<T>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for CovariantUnsafeCell<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>