pub trait FileBufRead<'a>: BufRead {
// Required methods
fn set_file(&mut self, file: &'a File, read_limit: FileSize) -> Result<()>;
fn add_file_to_prefetch(
&mut self,
file: &'a File,
read_limit: FileSize,
) -> Result<()>;
fn get_file_offset(&self) -> FileSize;
fn consume_or_skip(&mut self, n: usize);
}Expand description
An extension of the BufRead trait for file readers that allow tracking file
read position offset.
Required Methods§
Sourcefn set_file(&mut self, file: &'a File, read_limit: FileSize) -> Result<()>
fn set_file(&mut self, file: &'a File, read_limit: FileSize) -> Result<()>
Activate the given file as source of reads of this reader.
Resets the internal buffer to an empty state and sets the file offset to 0.
read_limit provides a pre-defined limit on the number of bytes that can be read
from the file (unless EOF is reached).
If the file was previously queued via add_file_to_prefetch, the reader
advances to that file (validating identity / read_limit) rather than
re-queueing it.
Sourcefn add_file_to_prefetch(
&mut self,
file: &'a File,
read_limit: FileSize,
) -> Result<()>
fn add_file_to_prefetch( &mut self, file: &'a File, read_limit: FileSize, ) -> Result<()>
Queue file for read-ahead (prefetch). Files are processed in FIFO order
by subsequent set_file calls.
This is a hint to keep the read pipeline saturated for readers that
support concurrent read-ahead. Implementations without read-ahead may
ignore the call. Callers must still invoke set_file to switch the
active file.
Sourcefn get_file_offset(&self) -> FileSize
fn get_file_offset(&self) -> FileSize
Returns the current file offset corresponding to the start of the buffer
that will be returned by the next call to fill_buf.
This offset represents the position within the underlying file where data will be consumed from.
Sourcefn consume_or_skip(&mut self, n: usize)
fn consume_or_skip(&mut self, n: usize)
Advance the offset by amt bytes, potentially skipping past the current buffer
into the underlying file.
Unlike BufRead::consume, amt is not constrained by the size of the buffer
returned by fill_buf — any bytes beyond what is currently buffered are skipped
by advancing the file read offset, so the next fill_buf starts at the correct
position.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".