Skip to main content

ManualAllocator

Struct ManualAllocator 

Source
pub struct ManualAllocator(/* private fields */);
Expand description

A singleton allocator that carries no underlying BStack and never allocates.

ManualAllocator is for code that wants the BStackSlice type — a typed (offset, len) handle with the standard slice interface — but manages positions on the backing BStack directly, without delegating region tracking to an allocator.

§Behaviour

OperationBehaviour
allocReturns Err(Unsupported)
reallocReturns Err(Unsupported)
deallocReturns Ok(()) (no-op)
lenReturns Err(Unsupported)
is_emptyReturns Err(Unsupported)
stackPanics — no backing stack
into_stackPanics — no backing stack

§Singleton

Obtain the allocator via ManualAllocator::get, which always returns the same &'static ManualAllocator. Direct construction is intentionally prevented to make the singleton nature explicit and to discourage treating the type as a regular value.

§Creating slices

Use BStackSlice::from_raw_parts to create a slice at a known position:

let slice = unsafe { BStackSlice::from_raw_parts(ManualAllocator::get(), offset, len) };

Or reconstruct one from a serialised token:

let slice = unsafe { BStackSlice::from_bytes(ManualAllocator::get(), token) };

Because there is no backing BStack, calling BStackSlice::read or BStackSlice::write on such a slice will panic. The slice is useful as a typed coordinate — serialised, compared, sorted, stored alongside other data — while all I/O is performed directly on the BStack via BStack::get / BStack::set at the offsets the slice describes.

§Manual position management

Since no allocator tracks ownership, the caller is entirely responsible for ensuring that every (offset, len) pair describes a valid, live region within the backing BStack, that regions do not overlap unless intentional, and that the BStack is not truncated beneath a live slice. No bookkeeping or validation is performed on construction.

Implementations§

Source§

impl ManualAllocator

Source

pub fn get() -> &'static Self

Returns a reference to the global singleton instance.

Trait Implementations§

Source§

impl BStackAllocator for ManualAllocator

Source§

fn stack(&self) -> &BStack

Always panics — ManualAllocator has no backing BStack.

Use the BStack directly for all I/O.

Source§

fn into_stack(self) -> BStack

Always panics — ManualAllocator has no backing BStack to return.

Source§

fn alloc(&self, _len: u64) -> Result<BStackSlice<'_, Self>>

Always returns Err(Unsupported).

Construct slices manually with BStackSlice::from_raw_parts instead.

Source§

fn realloc<'a>( &'a self, _slice: BStackSlice<'a, Self>, _new_len: u64, ) -> Result<BStackSlice<'a, Self>>

Always returns Err(Unsupported).

Manage slice positions manually by creating new BStackSlice handles.

Source§

fn dealloc(&self, _slice: BStackSlice<'_, Self>) -> Result<()>

Always returns Ok(()).

There is nothing to free — ownership of the region is the caller’s responsibility.

Source§

fn len(&self) -> Result<u64>

Always returns Err(Unsupported) — there is no backing BStack.

Source§

fn is_empty(&self) -> Result<bool>

Always returns Err(Unsupported) — there is no backing BStack.

Source§

type Error = Error

The error type returned by alloc, realloc, dealloc, alloc_bulk, and dealloc_bulk. Read more
Source§

type Allocated<'a> = BStackSlice<'a, ManualAllocator>

The handle type returned by alloc and realloc, and accepted by realloc and dealloc. Read more

Auto Trait Implementations§

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 = 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 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.
Source§

impl<A> BStackSliceAllocator for A
where A: BStackAllocator<Error = Error, Allocated<'a> = BStackSlice<'a, A>> + for<'a> BStackAllocator + 'static,