Skip to main content

CovariantUnsafeCell

Struct CovariantUnsafeCell 

Source
#[repr(transparent)]
pub struct CovariantUnsafeCell<T: ?Sized>(UnsafeCell<T>);
🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)
Expand description

Covariant version of UnsafeCell.

Tuple Fields§

§0: UnsafeCell<T>
🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)

Implementations§

Source§

impl<T> CovariantUnsafeCell<T>

Source

pub const fn new(value: T) -> CovariantUnsafeCell<T>

🔬This is a nightly-only experimental API. (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
#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;

let uc = CovariantUnsafeCell::new(5);
Source

pub const fn into_inner(self) -> T

🔬This is a nightly-only experimental API. (covariant_unsafe_cell #159735)

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();
Source§

impl<T: ?Sized> CovariantUnsafeCell<T>

Source

pub const fn get(&self) -> NonNull<T>

🔬This is a nightly-only experimental API. (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
#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;
use std::ptr::NonNull;

let uc = CovariantUnsafeCell::new(5);

let ptr: NonNull<i32> = uc.get();
Source

pub const fn get_mut(&mut self) -> &mut T

🔬This is a nightly-only experimental API. (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
#![feature(covariant_unsafe_cell)]
use std::cell::CovariantUnsafeCell;

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

assert_eq!(*c.get_mut(), 6);
Source

pub const fn raw_get(this: *const Self) -> *mut T

🔬This is a nightly-only experimental API. (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§

Source§

impl<T: ?Sized> !Sync for CovariantUnsafeCell<T>

Source§

impl<T: CoerceUnsized<U>, U> CoerceUnsized<CovariantUnsafeCell<U>> for CovariantUnsafeCell<T>

Source§

impl<T: ?Sized> Debug for CovariantUnsafeCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type #102070)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.