Enum MaybeUninitAlloc

Source
pub enum MaybeUninitAlloc<T>
where T: ?Sized,
{ Init(OwnedAlloc<T>), Uninit(UninitAlloc<T>), }
Expand description

Pointer to memory allocaation that might be either initialized or uninitialized. For the drop checker, the type acts as if it contains a T due to usage of PhantomData<T>.

Variants§

§

Init(OwnedAlloc<T>)

Initialized allocation.

§

Uninit(UninitAlloc<T>)

Uninitialized allocation.

Implementations§

Source§

impl<T> MaybeUninitAlloc<T>

Source

pub fn or_init<F>(self, init: F) -> OwnedAlloc<T>
where F: FnOnce() -> T,

If the allocation was initialized, this is a no-op. If it wasn’t, the passed function is called and its return value is used to initialize the memory. In both cases, an allocation considered initialized is returned.

Source§

impl<T> MaybeUninitAlloc<T>
where T: ?Sized,

Source

pub unsafe fn or_init_in_place<F>(self, init: F) -> OwnedAlloc<T>
where F: FnOnce(&mut T),

If the allocation was initialized, this is a no-op. If it wasn’t, the passed function is called with a mutable reference to the uninitialized memory and the function is expected to initialize the memory. In both cases, an allocation considered initialized is returned.

§Safety

This function is unsafe because the passed function might not initialize the memory correctly.

Source

pub fn is_initialized(&self) -> bool

Tests if the allocation is initialized.

Source

pub fn is_uninitialized(&self) -> bool

Tests if the allocation is uninitialized.

Source

pub fn drop_in_place(self) -> UninitAlloc<T>

If the memory is initialized, this function drops its content. In any case, the allocation now with uninitialized content is returned.

Source

pub fn init_as_ok(self) -> Result<OwnedAlloc<T>, UninitAlloc<T>>

Encodes this type as a Result with an OwnedAlloc as Ok.

Source

pub fn uninit_as_ok(self) -> Result<UninitAlloc<T>, OwnedAlloc<T>>

Encodes this type as a Result with an UninitAlloc as Ok.

Source

pub fn modify<F, A>(&mut self, visit: F) -> Option<A>
where F: FnOnce(&mut T) -> A,

If the memory is uninitialized, None is returned. If it is initialized, the passed function is called with a mutable reference to the allocation, and its return value is wrapped into a Some.

Trait Implementations§

Source§

impl<T> Debug for MaybeUninitAlloc<T>
where T: ?Sized,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> From<OwnedAlloc<T>> for MaybeUninitAlloc<T>
where T: ?Sized,

Source§

fn from(alloc: OwnedAlloc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for MaybeUninitAlloc<T>

Source§

fn from(val: T) -> Self

Converts to this type from the input type.
Source§

impl<T> From<UninitAlloc<T>> for MaybeUninitAlloc<T>
where T: ?Sized,

Source§

fn from(alloc: UninitAlloc<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for MaybeUninitAlloc<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for MaybeUninitAlloc<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for MaybeUninitAlloc<T>
where T: Send + ?Sized,

§

impl<T> Sync for MaybeUninitAlloc<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for MaybeUninitAlloc<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for MaybeUninitAlloc<T>

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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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, 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.