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;
    fn replay(
        &self,
        buffer: NonZeroUsize,
        start_pos: u64,
    ) -> impl Future<Output = Result<impl Stream<Item = Result<(u64, Self::Item), Error>> + Send, Error>> + Send;
}
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

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().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<E: Clock + Storage + Metrics, A: CodecFixedShared> Reader for commonware_storage::journal::contiguous::fixed::Reader<'_, E, A>

Source§

type Item = A

Source§

impl<E: Clock + Storage + Metrics, V: CodecShared> Reader for commonware_storage::journal::contiguous::variable::Reader<'_, E, V>

Source§

type Item = V