Trait uninit::AsMaybeUninit

source ·
pub unsafe trait AsMaybeUninit {
    type Uninit: ?Sized + MaybeUninitExt<T = Self>;
    type SizedPart: Sized;

    // Required methods
    fn as_ref_uninit(&self) -> &Self::Uninit;
    unsafe fn as_mut_uninit(&mut self) -> &mut Self::Uninit;
    unsafe fn raw_as_uninit<'a>(raw: *const Self) -> &'a Self::Uninit;
    unsafe fn raw_mut_as_uninit<'a>(raw: *mut Self) -> &'a mut Self::Uninit;
}
Expand description

Converts a reference into its maybe-initialized form.

This trait allows you to use a unified API for MaybeUninit on sized and unsized types.

You probably don’t need to implement this trait yourself: it is automatically implemented for all T: Sized and [T].

Safety

  • Uninit must have the same layout as Self but with no requirement on its contents. See the MaybeUninit layout.
  • All methods return pointers that point to the same memory as their input.

Required Associated Types§

source

type Uninit: ?Sized + MaybeUninitExt<T = Self>

This type in its maybe-uninitialized form.

source

type SizedPart: Sized

The largest Sized element in Self, used to check for the absence of drop glue via a Copy bound.

For Self: Sized, this equals Self, but for [T] it is T.

Required Methods§

source

fn as_ref_uninit(&self) -> &Self::Uninit

Converts a &self to its maybe-initialized equivalent.

source

unsafe fn as_mut_uninit(&mut self) -> &mut Self::Uninit

Converts a &mut T to its maybe-initialized equivalent.

This converts a read-write-valid-values-only reference to a write-anything reference.

Safety

The same requirements as Out::as_mut_uninit. Care should be taken with usage of the output - uninitialized garbage must not be written.

source

unsafe fn raw_as_uninit<'a>(raw: *const Self) -> &'a Self::Uninit

Converts a raw pointer to a reference to maybe-uninit.

Safety

This has the same requirements as &*(raw as *const Self::Uninit).

  • raw must point to a readable allocated memory for 'a for the size of T
  • raw must be aligned for T
source

unsafe fn raw_mut_as_uninit<'a>(raw: *mut Self) -> &'a mut Self::Uninit

Converts a raw mutable pointer to a mutable reference to maybe-uninit.

Safety

This has the same requirements as &mut *(raw as *mut Self::Uninit).

  • raw must point to a readable and writeable allocated object for 'a for the size of T
  • The pointer must not alias any other mutable references for 'a
  • raw must be aligned for T

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> AsMaybeUninit for [T]

§

type Uninit = [MaybeUninit<T>]

§

type SizedPart = T

source§

fn as_ref_uninit(&self) -> &Self::Uninit

source§

unsafe fn as_mut_uninit(&mut self) -> &mut Self::Uninit

source§

unsafe fn raw_as_uninit<'a>(raw: *const Self) -> &'a Self::Uninit

source§

unsafe fn raw_mut_as_uninit<'a>(raw: *mut Self) -> &'a mut Self::Uninit

Implementors§

source§

impl<T> AsMaybeUninit for T

§

type Uninit = MaybeUninit<T>

§

type SizedPart = T