Skip to main content

ReadAt

Trait ReadAt 

Source
pub trait ReadAt: Send + Sync {
    // Required methods
    fn len(&self) -> Result<u64>;
    fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize>;

    // Provided method
    fn is_empty(&self) -> Result<bool> { ... }
}
Expand description

Thread-safe positional compressed input.

Calls to ReadAt::read_at can occur concurrently and must not mutate a shared stream cursor. Implementations may return short reads, but must not return Ok(0) before the requested offset reaches ReadAt::len. The reported length and every byte before it must remain stable for the complete decode. Violating these requirements can cause an ordinary decoding error, but cannot violate memory safety because the trait is safe.

Required Methods§

Source

fn len(&self) -> Result<u64>

Returns the current source length in bytes.

Source

fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize>

Reads at most buffer.len() bytes beginning at offset.

An empty buffer returns zero. A non-empty buffer returns zero only when offset is at or beyond the current source length.

Provided Methods§

Source

fn is_empty(&self) -> Result<bool>

Returns whether this source is empty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ReadAt for File

Available on Unix only.
Source§

fn len(&self) -> Result<u64>

Source§

fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize>

Source§

impl ReadAt for Vec<u8>

Source§

fn len(&self) -> Result<u64>

Source§

fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize>

Source§

impl ReadAt for [u8]

Source§

fn len(&self) -> Result<u64>

Source§

fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize>

Source§

impl<T: ReadAt + ?Sized> ReadAt for Arc<T>

Source§

fn len(&self) -> Result<u64>

Source§

fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize>

Source§

impl<T: ReadAt + ?Sized> ReadAt for Box<T>

Source§

fn len(&self) -> Result<u64>

Source§

fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize>

Implementors§