Struct owned_alloc::UninitAlloc
source · pub struct UninitAlloc<T>where
T: ?Sized,{ /* private fields */ }
Expand description
Dynamic allocation of a T
whose memory is considered uninitialized. The
allocation is freed on drop
. If the size of the allocation is zero, no
allocation is performed and a dangling pointer is used (just like in std
).
For the drop checker, the type acts as if it contains a T
due to usage of
PhantomData<T>
.
Implementations
sourceimpl<T> UninitAlloc<T>
impl<T> UninitAlloc<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates room for a T
. In case of allocation error, the handler
registered via stdlib is called.
sourcepub fn try_new() -> Result<Self, AllocErr>
pub fn try_new() -> Result<Self, AllocErr>
Creates room for a T
. In case of allocation error, Err
is returned.
sourcepub fn init(self, val: T) -> OwnedAlloc<T>
pub fn init(self, val: T) -> OwnedAlloc<T>
Initializes the memory and returns the allocation now considered initialized.
sourceimpl<T> UninitAlloc<T>where
T: ?Sized,
impl<T> UninitAlloc<T>where
T: ?Sized,
sourcepub unsafe fn init_in_place<F>(self, init: F) -> OwnedAlloc<T>where
F: FnOnce(&mut T),
pub unsafe fn init_in_place<F>(self, init: F) -> OwnedAlloc<T>where
F: FnOnce(&mut T),
Calls a function with a mutable reference to uninitialized memory and returns the allocation now considered initialized. The passed function is expected to initialize the memory.
Safety
This function is unsafe
because the passed function might not
initialize the memory correctly.