pub struct MutableBlock<T: BlockMetadata> { /* private fields */ }Expand description
RAII guard for a block in the Reset state.
Wraps an internal Block<T, Reset> and guarantees that the block is
returned to the reset pool when the guard is dropped – whether the
caller explicitly transitions it or simply lets it fall out of scope.
§Obtaining a MutableBlock
BlockManager::allocate_blocks– pulls one or more blocks from the reset pool.CompleteBlock::reset– undoes a staging operation, returning a block to the Reset state (metrics are not carried over on this path).
§State transitions
stage– transitions toCompleteBlockusing a pre-computedSequenceHashand a block-size check.complete– transitions toCompleteBlockby extracting the hash from aTokenBlock.
Both methods consume self and return the block inside
Err(BlockError) on size mismatch so it is never leaked.
§Drop behaviour
Dropping a MutableBlock returns the underlying block to the reset pool
and decrements the inflight_mutable metric gauge.
Implementations§
Source§impl<T: BlockMetadata> MutableBlock<T>
impl<T: BlockMetadata> MutableBlock<T>
Sourcepub fn stage(
self,
seq_hash: SequenceHash,
block_size: usize,
) -> Result<CompleteBlock<T>, BlockError<MutableBlock<T>>>
pub fn stage( self, seq_hash: SequenceHash, block_size: usize, ) -> Result<CompleteBlock<T>, BlockError<MutableBlock<T>>>
Transitions from Reset to Staged, producing a CompleteBlock.
The caller supplies a pre-computed SequenceHash and the expected
block_size. If block_size does not match the block’s fixed size
the method returns Err(BlockError::BlockSizeMismatch) with the
MutableBlock inside so the caller can recover it.
Increments the stagings counter on success.
Sourcepub fn complete(
self,
token_block: &TokenBlock,
) -> Result<CompleteBlock<T>, BlockError<MutableBlock<T>>>
pub fn complete( self, token_block: &TokenBlock, ) -> Result<CompleteBlock<T>, BlockError<MutableBlock<T>>>
Transitions from Reset to Staged, producing a CompleteBlock.
The SequenceHash is derived from the provided
TokenBlock. If the token block’s size
does not match the block’s fixed size the method returns
Err(BlockError::BlockSizeMismatch) with the MutableBlock
inside so the caller can recover it.
Increments the stagings counter on success.