Expand description
A pointer type for memory allocation.
Implementations
sourceimpl<T: ?Sized, A: Allocator> Box<T, A>
impl<T: ?Sized, A: Allocator> Box<T, A>
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 a box from a raw pointer in the given allocator.
After calling this function, the raw pointer is owned by the resulting
Box. Specifically, the Box destructor will call the 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 Box.
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 fn into_raw_with_allocator(b: Self) -> (*mut T, A)
pub fn into_raw_with_allocator(b: Self) -> (*mut T, A)
Consumes the Box, 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 Box. In particular, the caller should
properly destroy T and release the memory, taking into account the
memory layout used by Box. The easiest way to do this is to convert
the raw pointer back into a Box with the Box::from_raw_in function,
allowing the Box destructor to perform the cleanup.
Note: this is an associated function, which means that you have to call
it as Box::into_raw_with_allocator(b) instead of
b.into_raw_with_allocator(). This is so that there is no conflict with
a method on the inner type.