Skip to main content

LogicalBlockAssignments

Struct LogicalBlockAssignments 

Source
pub struct LogicalBlockAssignments<T: BlockMetadata> { /* private fields */ }
Expand description

Manages the physical block guards (RAII types) through three ordered collections, mirroring the block lifecycle state machine: MutableBlock<T>CompleteBlock<T>ImmutableBlock<T>.

Provides the same ordered-collection semantics as ExternalBlockAssignments but at the guard level rather than the identity level.

Implementations§

Source§

impl<T: BlockMetadata> LogicalBlockAssignments<T>

Source

pub fn new() -> Self

Creates an empty LogicalBlockAssignments.

Source

pub fn assigned_count(&self) -> usize

Returns the number of assigned (registered/immutable) blocks.

Source

pub fn staged_count(&self) -> usize

Returns the number of staged (complete) blocks.

Source

pub fn unassigned_count(&self) -> usize

Returns the number of unassigned (mutable) blocks.

Source

pub fn is_empty(&self) -> bool

Returns true if all three collections are empty.

Source

pub fn contains(&self, block_id: &BlockId) -> bool

Checks whether a BlockId is present in any of the three collections.

Source

pub fn get_assigned( &self, index: usize, ) -> Option<(&BlockId, &ImmutableBlock<T>)>

Returns the assigned block at the given index (insertion order).

Source

pub fn get_staged(&self, index: usize) -> Option<(&BlockId, &CompleteBlock<T>)>

Returns the staged block at the given index (staging order).

Source

pub fn get_unassigned( &self, index: usize, ) -> Option<(&BlockId, &MutableBlock<T>)>

Returns the unassigned block at the given index (FIFO order).

Source

pub fn assigned_iter( &self, ) -> impl Iterator<Item = (&BlockId, &ImmutableBlock<T>)>

Iterates over assigned blocks in positional order.

Source

pub fn staged_iter(&self) -> impl Iterator<Item = (&BlockId, &CompleteBlock<T>)>

Iterates over staged blocks in staging order.

Source

pub fn unassigned_iter( &self, ) -> impl Iterator<Item = (&BlockId, &MutableBlock<T>)>

Iterates over unassigned blocks in FIFO order.

Source

pub fn all_block_ids(&self) -> impl Iterator<Item = &BlockId>

Iterates over all block IDs across all three collections in lifecycle order: assigned → staged → unassigned.

Source

pub fn extend_blocks( &mut self, blocks: impl IntoIterator<Item = MutableBlock<T>>, ) -> Result<usize, LogicalBlockAssignmentError<T>>

Adds mutable blocks to the unassigned queue.

Two-phase atomic: collects all blocks, validates no duplicate BlockIds across all three collections, then commits to unassigned. On error, all blocks are returned in the error variant (no leaks).

Source

pub fn extend_assigned( &mut self, blocks: impl IntoIterator<Item = ImmutableBlock<T>>, ) -> Result<usize, LogicalBlockAssignmentError<T>>

Inserts pre-matched immutable blocks directly into the assigned collection.

This is the entry point for blocks retrieved via BlockManager::match_blocks — blocks that already exist in the manager’s pools and can skip the unassigned → staged → assigned pipeline.

Two-phase atomic: collects all blocks, validates no duplicate BlockIds across all three collections, then commits to assigned. On error, all blocks are returned in the error variant (no leaks).

Source

pub fn stage( &mut self, sequence_blocks: &[TokenBlock], ) -> Result<usize, BlockError<MutableBlock<T>>>

FIFO drain from unassigned, completing each block with the corresponding token block.

Stages min(sequence_blocks.len(), unassigned.len()) blocks. On BlockError, already-staged blocks remain in staged; the failed block is returned in the error.

Source

pub fn register(&mut self, manager: &BlockManager<T>) -> usize

Takes all staged blocks (FIFO order), registering each with the block manager and moving them to assigned.

Returns the number of blocks registered.

Source

pub fn pop_last_unassigned(&mut self) -> Option<(BlockId, MutableBlock<T>)>

LIFO-removes the last unassigned block.

Source

pub fn clear(&mut self)

Drops all guards across all three collections (RAII returns blocks to pools).

Source

pub fn take_assigned(&mut self) -> Vec<(BlockId, ImmutableBlock<T>)>

Takes all assigned blocks, returning them as a Vec.

Source

pub fn take_staged(&mut self) -> Vec<(BlockId, CompleteBlock<T>)>

Takes all staged blocks, returning them as a Vec.

Source

pub fn take_unassigned(&mut self) -> Vec<(BlockId, MutableBlock<T>)>

Takes all unassigned blocks, returning them as a Vec.

Trait Implementations§

Source§

impl<T: BlockMetadata> Debug for LogicalBlockAssignments<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: BlockMetadata> Default for LogicalBlockAssignments<T>

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more