pub trait DataRead {
Show 13 methods
// Required methods
fn stream_position(&self) -> u64;
fn read_range(&mut self, range: Range<u64>) -> Result<&[u8], Error>;
fn read_until_any_delim_or_limit(
&mut self,
delims: &[u8],
limit: u64,
) -> Result<&[u8], Error>;
fn read_until_or_limit(
&mut self,
byte: u8,
limit: u64,
) -> Result<&[u8], Error>;
fn read_while_or_limit<F>(
&mut self,
f: F,
limit: u64,
) -> Result<&[u8], Error>
where F: Fn(u8) -> bool;
fn read_until_utf16_or_limit(
&mut self,
utf16_char: &[u8; 2],
limit: u64,
) -> Result<&[u8], Error>;
fn data_size(&self) -> u64;
fn seek(&mut self, pos: SeekFrom) -> Result<u64>;
// Provided methods
fn offset_from_start(&self, pos: SeekFrom) -> u64 { ... }
fn read_count(&mut self, count: u64) -> Result<&[u8], Error> { ... }
fn read_exact_range(&mut self, range: Range<u64>) -> Result<&[u8], Error> { ... }
fn read_exact_count(&mut self, count: u64) -> Result<&[u8], Error> { ... }
fn read_exact_into(&mut self, buf: &mut [u8]) -> Result<(), Error> { ... }
}Expand description
A trait for reading data with position tracking and range-based access.
Implementors provide efficient random access to byte data for file magic detection, supporting both in-memory and file-backed storage.
Required Methods§
Sourcefn stream_position(&self) -> u64
fn stream_position(&self) -> u64
Returns the current position in the data stream.
Sourcefn read_range(&mut self, range: Range<u64>) -> Result<&[u8], Error>
fn read_range(&mut self, range: Range<u64>) -> Result<&[u8], Error>
Reads a range of bytes from the data.
Returns an empty slice if the range is beyond the end of data.
Sourcefn read_until_any_delim_or_limit(
&mut self,
delims: &[u8],
limit: u64,
) -> Result<&[u8], Error>
fn read_until_any_delim_or_limit( &mut self, delims: &[u8], limit: u64, ) -> Result<&[u8], Error>
Reads bytes until any of the delimiters or limit bytes is reached.
The delimiter byte is included in the returned slice.
Sourcefn read_until_or_limit(&mut self, byte: u8, limit: u64) -> Result<&[u8], Error>
fn read_until_or_limit(&mut self, byte: u8, limit: u64) -> Result<&[u8], Error>
Reads bytes until byte or limit bytes is reached.
The delimiter byte is included in the returned slice.
Sourcefn read_while_or_limit<F>(&mut self, f: F, limit: u64) -> Result<&[u8], Error>
fn read_while_or_limit<F>(&mut self, f: F, limit: u64) -> Result<&[u8], Error>
Reads bytes while f returns true or until limit bytes is reached.
The byte that caused f to return false is not included.
Provided Methods§
Sourcefn offset_from_start(&self, pos: SeekFrom) -> u64
fn offset_from_start(&self, pos: SeekFrom) -> u64
Computes the absolute byte offset from a SeekFrom position.
Sourcefn read_count(&mut self, count: u64) -> Result<&[u8], Error>
fn read_count(&mut self, count: u64) -> Result<&[u8], Error>
Reads up to count bytes from the current position.
Returns fewer bytes if the end of data is reached.
Sourcefn read_exact_range(&mut self, range: Range<u64>) -> Result<&[u8], Error>
fn read_exact_range(&mut self, range: Range<u64>) -> Result<&[u8], Error>
Reads exactly the specified byte range.
§Errors
Returns an error if the range extends beyond the available data.
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.