pub struct Stream<'index, Reader> { /* private fields */ }Expand description
Implementations§
Source§impl<'index, R: Read> Stream<'index, R>
impl<'index, R: Read> Stream<'index, R>
Sourcepub fn locate(&mut self, offset: Offset, buf: &mut [u8]) -> Result<ZeroBased>
pub fn locate(&mut self, offset: Offset, buf: &mut [u8]) -> Result<ZeroBased>
Locate the (line, column) position for a given byte offset.
NOTE: this method may cause extra reading when the offset input cannot find a location.
This method first resolves the line index via [locate_line], then
computes the column by subtracting the starting offset of that line.
§Parameters
offset: The target byte offset.buf: A temporary buffer used for incremental reading.
§Returns
Ok(ZeroBased(line, column))if the offset is within bounds.Errif the offset exceeds EOF (propagated from [locate_line]).
§Invariants
- The internal index always contains a valid starting offset for every line.
- Therefore,
line_offset(line)must succeed for any validline.
§Notes
- Both line and column are zero-based.
- Column is computed in bytes, not characters (UTF-8 aware handling is not performed here).
Sourcepub fn locate_line(&mut self, offset: Offset, buf: &mut [u8]) -> Result<usize>
pub fn locate_line(&mut self, offset: Offset, buf: &mut [u8]) -> Result<usize>
Locate the line index for a given byte offset.
This method performs an incremental lookup: it first queries the existing line index, and if the offset is not covered, it reads more data and extends the index. This method may cause extra reading when the offset input cannot find a location.
§Invariants
- The internal index is non-empty and ends with a sentinel EOF offset.
§Errors
Returns an error if offset exceeds EOF.
Sourcepub fn encode(
&mut self,
line_index: ZeroBased,
buf: &mut [u8],
) -> Result<Offset>
pub fn encode( &mut self, line_index: ZeroBased, buf: &mut [u8], ) -> Result<Offset>
Encode a (line, column) location into a byte Offset.
This method may incrementally extend the internal line index by reading additional data if the requested line is not yet available.
§Behavior
- If the line is already indexed, the offset is computed directly.
- Otherwise, more data is read and the index is extended until the line becomes available or EOF is reached.
§Returns
Ok(offset)if the position can be resolved.Errif the line index exceeds EOF.
§Notes
- Column is interpreted as a byte offset relative to the start of the line.
- This method does not validate whether the column lies within the bounds of the line.
Trait Implementations§
Source§impl<'index, R: Read> Read for Stream<'index, R>
impl<'index, R: Read> Read for Stream<'index, R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
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 more