Skip to main content

Reader

Trait Reader 

Source
pub trait Reader: Send + Sync {
    type Item;

    // Required methods
    fn bounds(&self) -> Range<u64>;
    fn read(
        &self,
        position: u64,
    ) -> impl Future<Output = Result<Self::Item, Error>> + Send + Sync;
    fn replay(
        &self,
        buffer: NonZeroUsize,
        start_pos: u64,
    ) -> impl Future<Output = Result<impl Stream<Item = Result<(u64, Self::Item), Error>> + Send, Error>> + Send;

    // Provided methods
    fn read_many(
        &self,
        positions: &[u64],
    ) -> impl Future<Output = Result<Vec<Self::Item>, Error>> + Send
       where Self::Item: Send { ... }
    fn try_read_sync(&self, _position: u64) -> Option<Self::Item> { ... }
}
Expand description

A reader guard that holds a consistent view of the journal.

While this guard exists, operations that may modify the bounds (such as append, prune, and rewind) will block until the guard is dropped. This keeps bounds stable, so any position within bounds() is guaranteed readable.

Required Associated Types§

Source

type Item

The type of items stored in the journal.

Required Methods§

Source

fn bounds(&self) -> Range<u64>

Returns [start, end) with a guaranteed stable pruning boundary.

Source

fn read( &self, position: u64, ) -> impl Future<Output = Result<Self::Item, Error>> + Send + Sync

Read the item at the given position.

Guaranteed not to return Error::ItemPruned for positions within bounds().

Source

fn replay( &self, buffer: NonZeroUsize, start_pos: u64, ) -> impl Future<Output = Result<impl Stream<Item = Result<(u64, Self::Item), Error>> + Send, Error>> + Send

Return a stream of all items starting from start_pos.

Because the reader holds the lock, validation and stream setup happen atomically with respect to prune().

Provided Methods§

Source

fn read_many( &self, positions: &[u64], ) -> impl Future<Output = Result<Vec<Self::Item>, Error>> + Send
where Self::Item: Send,

Read multiple items at the given positions, which must be strictly increasing.

The default implementation calls read in a loop. Concrete journal implementations override this to amortize lock acquisition and batch I/O.

Source

fn try_read_sync(&self, _position: u64) -> Option<Self::Item>

Read an item if it can be done synchronously (e.g. without I/O), returning None otherwise.

Default implementation always returns None.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<E: Context, A: CodecFixedShared> Reader for commonware_storage::journal::contiguous::fixed::Reader<'_, E, A>

Source§

type Item = A

Source§

impl<E: Context, V: CodecShared> Reader for commonware_storage::journal::contiguous::variable::Reader<'_, E, V>

Source§

type Item = V