Expand description
A pointer type for memory allocation.
Implementations
sourceimpl<T: DropRaw + ?Sized, A: Allocator> OwnedVal<T, A>
impl<T: DropRaw + ?Sized, A: Allocator> OwnedVal<T, A>
sourcepub fn allocator(v: &Self) -> &A
pub fn allocator(v: &Self) -> &A
Returns a reference to the underlying allocator.
Note: this is an associated function, which means that you have to call
it as OwnedVal::allocator(&v) instead of owned_val.allocator(). This
is so that there is no conflict with a method on the inner type.
sourcepub unsafe fn from_raw_in(ptr: *mut T, alloc: A) -> Self
pub unsafe fn from_raw_in(ptr: *mut T, alloc: A) -> Self
Constructs an owned Val from a raw pointer in the given allocator.
After calling this function, the raw pointer is owned by the resulting
OwnedVal. Specifically, the OwnedVal destructor will call the
DropRaw destructor of T and free the allocated memory. For this to
be safe, the memory must have been allocated in accordance with the
memory layout used by OwnedVal.
Safety
ptrmust point to a memory block currently allocated byalloc.- The layout used to allocate
ptrmust exactly match the return value ofLayout::for_value. ptrmust point to an initializedT.
sourcepub unsafe fn assume_init(frame: Frame<T, A>) -> Selfwhere
T: Pointee,
<T as Pointee>::Metadata: Metadata<T>,
pub unsafe fn assume_init(frame: Frame<T, A>) -> Selfwhere
T: Pointee,
<T as Pointee>::Metadata: Metadata<T>,
sourcepub fn into_raw_parts(b: Self) -> (*mut T, A)
pub fn into_raw_parts(b: Self) -> (*mut T, A)
Consumes the OwnedVal, returning a wrapped raw pointer and the
allocator.
The pointer will be properly aligned and non-null.
After calling this function, the caller is responsible for the memory
previously managed by the OwnedVal. In particular, the caller should
properly destroy T with DropRaw and release the memory, taking into
account the memory layout used by OwnedVal. The easiest way to do this
is to convert the raw pointer back into an OwnedVal with the
OwnedVal::from_raw_in function, allowing the OwnedVal destructor to
perform the cleanup.
Note: this is an associated function, which means that you have to call
it as OwnedVal::into_raw(b) instead of b.into_raw(). This is so that
there is no conflict with a method on the inner type.