Struct presser::RawAllocation
source · pub struct RawAllocation {
pub base_ptr: NonNull<u8>,
pub size: usize,
}
Expand description
Represents a contiguous piece of a single allocation with some layout. May be wholly or partially uninitialized.
This exists as a convenient way to get access to a type implementing Slab
when dealing with your own raw allocations/buffers if you don’t want to or
cannot implement Slab
for another native type.
Fields§
§base_ptr: NonNull<u8>
A pointer to the base address of the allocation
size: usize
The size of the allocation in bytes
Implementations§
source§impl RawAllocation
impl RawAllocation
sourcepub fn from_raw_parts(base_ptr: NonNull<u8>, size: usize) -> Self
pub fn from_raw_parts(base_ptr: NonNull<u8>, size: usize) -> Self
Create a new RawAllocation
from a pointer and size.
Safety
This function is safe in and of itself, as nothing will be done with the pointer and size upon creation.
sourcepub unsafe fn borrow_as_slab<'a>(&'a mut self) -> BorrowedRawAllocation<'a>
pub unsafe fn borrow_as_slab<'a>(&'a mut self) -> BorrowedRawAllocation<'a>
Asserts that we are uniquely borrowing the memory range represented by self
for
the duration of the borrow, giving us a BorrowedRawAllocation
which implements Slab
.
Safety
Using this method makes some strong guarantees about the contained base_ptr
and size
for the duration of the borrow. See the safety documentation for the
Slab
trait for a list of the guarantees you must make to use this method.
Also see the top-level safety documentation