pub struct BStackReader<'a> { /* private fields */ }Expand description
A cursor-based reader over a BStack payload.
BStackReader implements io::Read and io::Seek, allowing the
stack’s payload to be consumed through any interface that expects a
readable, seekable byte stream.
§Construction
use bstack::BStack;
let stack = BStack::open("log.bin")?;
stack.push(b"hello world")?;
// Start reading from the beginning.
let mut reader = stack.reader();
// Or start from an arbitrary offset.
let mut mid = stack.reader_at(6);§Concurrency
BStackReader borrows the stack immutably, so multiple readers can coexist
and run concurrently with each other and with peek /
get calls. Concurrent push or
pop operations are not blocked by an active reader, but
reading interleaved with writes may observe different snapshots of the
payload across calls — callers are responsible for synchronisation when
that matters.
Implementations§
Trait Implementations§
Source§impl<'a> From<&'a BStack> for BStackReader<'a>
impl<'a> From<&'a BStack> for BStackReader<'a>
Source§impl<'a> Read for BStackReader<'a>
impl<'a> Read for BStackReader<'a>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Read bytes from the current position into buf.
Returns the number of bytes read, which may be less than buf.len() if
the end of the payload is reached. Returns Ok(0) at EOF.
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<'a> Seek for BStackReader<'a>
impl<'a> Seek for BStackReader<'a>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Move the read cursor.
SeekFrom::Start and SeekFrom::Current with a non-negative delta
may advance the cursor past the current end of the payload; subsequent
read calls will return Ok(0) until the payload
grows past that point. Seeking before the start of the payload returns
io::ErrorKind::InvalidInput.
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)