Struct owned_alloc::OwnedAlloc
source · pub struct OwnedAlloc<T>where
T: ?Sized,{ /* private fields */ }
Expand description
Dynamic allocation of a T
whose memory is considered fully initialized.
The allocation and its content are freed on drop
. Similar to a Box
. 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> OwnedAlloc<T>
impl<T> OwnedAlloc<T>
sourcepub fn new(val: T) -> Self
pub fn new(val: T) -> Self
Creates an allocation and initializes it to the passed argument. In case of allocation error, the handler registered via stdlib is called.
sourcepub fn try_new(val: T) -> Result<Self, AllocErr>
pub fn try_new(val: T) -> Result<Self, AllocErr>
Creates an allocation and initializes it to the passed argument. In case
of allocation error, Err
is returned.
sourcepub fn move_inner(self) -> (T, UninitAlloc<T>)
pub fn move_inner(self) -> (T, UninitAlloc<T>)
Moves the stored value out from the allocation. The value and the allocation now considered uninitialized are returned.
sourceimpl<T> OwnedAlloc<T>where
T: ?Sized,
impl<T> OwnedAlloc<T>where
T: ?Sized,
sourcepub unsafe fn from_raw(nnptr: NonNull<T>) -> Self
pub unsafe fn from_raw(nnptr: NonNull<T>) -> Self
Recreate the OwnedAlloc
from a raw non-null pointer.
Safety
This functions is unsafe
because passing the wrong pointer leads to
undefined behaviour. Passing a pointer to uninitialized memory is also
undefined behaviour.
sourcepub unsafe fn from_box(boxed: Box<T>) -> Self
pub unsafe fn from_box(boxed: Box<T>) -> Self
Converts the plain old standard library Box
into an owned allocation.
Safety
This function is unsafe
because there are no guarantees that Box
and
OwnedAlloc
allocate in the same way. They probably do in the Rust
version you are using, but there are no future guarantees.
sourcepub fn into_raw(self) -> NonNull<T>
pub fn into_raw(self) -> NonNull<T>
“Forgets” dropping both the allocation and its content and returns its raw non-null pointer.
sourcepub unsafe fn into_box(self) -> Box<T>
pub unsafe fn into_box(self) -> Box<T>
Converts the owned allocation into a plain old standard library Box
.
Safety
This function is unsafe
because there are no guarantees that Box
and
OwnedAlloc
allocate in the same way. They probably do in the Rust
version you are using, but there are no future guarantees.
sourcepub fn drop_in_place(self) -> UninitAlloc<T>
pub fn drop_in_place(self) -> UninitAlloc<T>
Drops the memory and returns the allocation now considered uninitialized.
sourcepub fn forget_inner(self) -> UninitAlloc<T>
pub fn forget_inner(self) -> UninitAlloc<T>
“Forgets” about dropping the inner value and returns an uninitialized allocation.