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 asSelf
but with no requirement on its contents. See theMaybeUninit
layout.- All methods return pointers that point to the same memory as their input.
Required Associated Types§
Sourcetype Uninit: ?Sized + MaybeUninitExt<T = Self>
type Uninit: ?Sized + MaybeUninitExt<T = Self>
This type in its maybe-uninitialized form.
Required Methods§
Sourcefn as_ref_uninit(&self) -> &Self::Uninit
fn as_ref_uninit(&self) -> &Self::Uninit
Converts a &self
to its maybe-initialized equivalent.
Sourceunsafe fn as_mut_uninit(&mut self) -> &mut Self::Uninit
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.
Sourceunsafe fn raw_as_uninit<'a>(raw: *const Self) -> &'a Self::Uninit
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 ofT
raw
must be aligned forT
Sourceunsafe fn raw_mut_as_uninit<'a>(raw: *mut Self) -> &'a mut Self::Uninit
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 ofT
- The pointer must not alias any other mutable references for
'a
raw
must be aligned forT
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.