Skip to main content

DataRead

Trait DataRead 

Source
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§

Source

fn stream_position(&self) -> u64

Returns the current position in the data stream.

Source

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.

Source

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.

Source

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.

Source

fn read_while_or_limit<F>(&mut self, f: F, limit: u64) -> Result<&[u8], Error>
where F: Fn(u8) -> bool,

Reads bytes while f returns true or until limit bytes is reached.

The byte that caused f to return false is not included.

Source

fn read_until_utf16_or_limit( &mut self, utf16_char: &[u8; 2], limit: u64, ) -> Result<&[u8], Error>

Reads bytes until a UTF-16 character or limit bytes is reached.

The UTF-16 character is included in the returned slice.

Source

fn data_size(&self) -> u64

Returns the total size of the data in bytes.

Source

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Sets the position for future reads.

Provided Methods§

Source

fn offset_from_start(&self, pos: SeekFrom) -> u64

Computes the absolute byte offset from a SeekFrom position.

Source

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.

Source

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.

Source

fn read_exact_count(&mut self, count: u64) -> Result<&[u8], Error>

Reads exactly count bytes from the current position.

§Errors

Returns an error if fewer than count bytes are available.

Source

fn read_exact_into(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads exactly enough bytes to fill buf.

§Errors

Returns an error if fewer than buf.len() bytes are available.

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.

Implementors§

Source§

impl DataRead for DataReader<'_>

Source§

impl<R> DataRead for LazyCache<R>
where R: Read + Seek,

Source§

impl<S> DataRead for BufReader<S>
where S: AsRef<[u8]>,