Enum owned_alloc::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
Implementations
sourceimpl<T> MaybeUninitAlloc<T>
impl<T> MaybeUninitAlloc<T>
sourcepub fn or_init<F>(self, init: F) -> OwnedAlloc<T>where
F: FnOnce() -> T,
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.
sourceimpl<T> MaybeUninitAlloc<T>where
T: ?Sized,
impl<T> MaybeUninitAlloc<T>where
T: ?Sized,
sourcepub unsafe fn or_init_in_place<F>(self, init: F) -> OwnedAlloc<T>where
F: FnOnce(&mut T),
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.
sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Tests if the allocation is initialized.
sourcepub fn is_uninitialized(&self) -> bool
pub fn is_uninitialized(&self) -> bool
Tests if the allocation is uninitialized.
sourcepub fn drop_in_place(self) -> UninitAlloc<T>
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.
sourcepub fn init_as_ok(self) -> Result<OwnedAlloc<T>, UninitAlloc<T>>
pub fn init_as_ok(self) -> Result<OwnedAlloc<T>, UninitAlloc<T>>
Encodes this type as a Result
with an OwnedAlloc
as Ok
.
sourcepub fn uninit_as_ok(self) -> Result<UninitAlloc<T>, OwnedAlloc<T>>
pub fn uninit_as_ok(self) -> Result<UninitAlloc<T>, OwnedAlloc<T>>
Encodes this type as a Result
with an UninitAlloc
as Ok
.