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

source

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.

source

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.