Skip to main content

Heap

Struct Heap 

Source
pub struct Heap<'brand, P, B = MemoryBackendWrapper>{ /* private fields */ }
Expand description

A scoped, lifetime-branded memory heap.

Heap is the single public heap surface. It statically validates local block ownership through the scoped brand lifetime while delegating all allocation mechanics to the monomorphized RawHeap core.

Implementations§

Source§

impl<'brand, P, B> Heap<'brand, P, B>

Source

pub fn alloc<Permit>( &self, _permit: Permit, layout: Layout, ) -> Option<BrandedBlock<'brand, u8>>
where Permit: ReadPermit<'brand>,

Allocates a block of memory from this heap.

The block is tied to the heap’s unique 'brand lifetime. Returns None if the allocation fails. The read permit proves that the request belongs to this brand without adding runtime state.

Source

pub fn free<T, Permit>( &self, _permit: &mut Permit, block: BrandedBlock<'brand, T>, )
where &'token mut Permit: for<'token> WritePermit<'brand>, T: ?Sized,

Frees a block of memory back to this heap, dropping the value in-place first.

Because the block is branded with the heap’s unique 'brand lifetime, it is statically guaranteed to have been allocated by this heap. The write permit proves exclusive access while the value is dropped.

The block is returned to the heap even if T’s destructor panics.

Source

pub fn free_uninit<T, Permit>( &self, _permit: &mut Permit, block: BrandedBlock<'brand, T>, )
where &'token mut Permit: for<'token> WritePermit<'brand>, T: ?Sized,

Frees a block of memory back to this heap without dropping the value.

Useful for uninitialized memory or manual drop management.

Source

pub fn alloc_init<T, Permit>( &self, permit: Permit, val: T, ) -> Option<BrandedBlock<'brand, T>>
where Permit: ReadPermit<'brand>,

Allocates and initializes a value directly in a branded memory block.

The block is guaranteed to contain a fully initialized value of type T.

Source

pub fn realloc<T, Permit>( &self, permit: &mut Permit, block: BrandedBlock<'brand, T>, layout: Layout, new_size: usize, ) -> Result<Option<BrandedBlock<'brand, u8>>, ReallocError<'brand, T>>
where &'token mut Permit: for<'token> WritePermit<'brand>, T: ?Sized,

Reallocates a memory block from this heap.

The source block is returned inside ReallocError when the requested layout is invalid or replacement allocation fails, so failure does not leak or invalidate the original allocation. A new_size of zero frees the source block and returns Ok(None). layout must describe the source allocation; the boundary rejects sizes beyond the allocator’s usable capacity and source-pointer alignment mismatches.

§Errors

Returns ReallocError with the original source block when the new layout is invalid or replacement allocation fails.

Trait Implementations§

Source§

impl<'brand, P, B> Send for Heap<'brand, P, B>

Auto Trait Implementations§

§

impl<'brand, P, B = MemoryBackendWrapper> !Freeze for Heap<'brand, P, B>

§

impl<'brand, P, B = MemoryBackendWrapper> !RefUnwindSafe for Heap<'brand, P, B>

§

impl<'brand, P, B = MemoryBackendWrapper> !Sync for Heap<'brand, P, B>

§

impl<'brand, P, B> Unpin for Heap<'brand, P, B>
where RawHeap<P, B>: Unpin,

§

impl<'brand, P, B> UnsafeUnpin for Heap<'brand, P, B>
where RawHeap<P, B>: UnsafeUnpin,

§

impl<'brand, P, B> UnwindSafe for Heap<'brand, P, B>
where RawHeap<P, B>: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.