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 CovariantUnsafeCell which will wrap the specified value.

All access to the inner value through &CovariantUnsafeCell<T> requires unsafe code.

Examples

#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;

let uc = CovariantUnsafeCell::new(5);
const fn into_inner(self) -> T

Unwraps the value, consuming the cell.

Examples

#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;

let uc = CovariantUnsafeCell::new(5);

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 UnsafeCell type-level docs for more discussion and caveats.

Examples

#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;
use std::ptr::NonNull;

let uc = CovariantUnsafeCell::new(5);

let ptr: NonNull<i32> = uc.get();
const fn get_mut(&mut self) -> &mut T

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

#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;

let mut c = CovariantUnsafeCell::new(5);
*c.get_mut() += 1;

assert_eq!(*c.get_mut(), 6);
const fn raw_get(this: *const Self) -> *mut T

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: ?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) -> T

Returns the argument unchanged.

impl<T> SizeHint for CovariantUnsafeCell<T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn 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) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses 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>