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;
// Provided method
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
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().
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 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", so this trait is not object safe.