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§
Required Methods§
Sourcefn read(
&self,
position: u64,
) -> impl Future<Output = Result<Self::Item, Error>> + Send + Sync
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().
Sourcefn replay(
&self,
buffer: NonZeroUsize,
start_pos: u64,
) -> impl Future<Output = Result<impl Stream<Item = Result<(u64, Self::Item), Error>> + Send, 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
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§
Sourcefn read_many(
&self,
positions: &[u64],
) -> impl Future<Output = Result<Vec<Self::Item>, Error>> + Send
fn read_many( &self, positions: &[u64], ) -> impl Future<Output = Result<Vec<Self::Item>, Error>> + 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.
Sourcefn try_read_sync(&self, _position: u64) -> Option<Self::Item>
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".