Trait AsyncSliceReader

Source
pub trait AsyncSliceReader {
    // Required methods
    fn read_at(
        &mut self,
        offset: u64,
        len: usize,
    ) -> impl Future<Output = Result<Bytes, Error>>;
    fn size(&mut self) -> impl Future<Output = Result<u64, Error>>;

    // Provided method
    fn read_exact_at(
        &mut self,
        offset: u64,
        len: usize,
    ) -> impl Future<Output = Result<Bytes, Error>> { ... }
}
Expand description

A trait to abstract async reading from different resource.

This trait does not require the notion of a current position, but instead requires explicitly passing the offset to read_at. In addition to the ability to read at an arbitrary offset, it also provides the ability to get the length of the resource.

This is similar to the io interface of sqlite. See xRead, xFileSize in https://www.sqlite.org/c3ref/io_methods.html

Required Methods§

Source

fn read_at( &mut self, offset: u64, len: usize, ) -> impl Future<Output = Result<Bytes, Error>>

Read the entire buffer at the given position.

Will return at most len bytes, but may return fewer if the resource is smaller. If the range is completely covered by the resource, will return exactly len bytes. If the range is not covered at all by the resource, will return an empty buffer. It will never return an io error independent of the range as long as the underlying resource is valid.

Source

fn size(&mut self) -> impl Future<Output = Result<u64, Error>>

Get the length of the resource

Provided Methods§

Source

fn read_exact_at( &mut self, offset: u64, len: usize, ) -> impl Future<Output = Result<Bytes, Error>>

Variant of read_at that returns an error if less than len bytes are read.

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.

Implementations on Foreign Types§

Source§

impl AsyncSliceReader for &[u8]

Source§

async fn read_at(&mut self, offset: u64, len: usize) -> Result<Bytes, Error>

Source§

async fn size(&mut self) -> Result<u64, Error>

Source§

impl AsyncSliceReader for Bytes

Source§

async fn read_at(&mut self, offset: u64, len: usize) -> Result<Bytes, Error>

Source§

async fn size(&mut self) -> Result<u64, Error>

Source§

impl AsyncSliceReader for BytesMut

Source§

async fn read_at(&mut self, offset: u64, len: usize) -> Result<Bytes, Error>

Source§

async fn size(&mut self) -> Result<u64, Error>

Source§

impl<T> AsyncSliceReader for &mut T

Source§

async fn read_at(&mut self, offset: u64, len: usize) -> Result<Bytes, Error>

Source§

async fn size(&mut self) -> Result<u64, Error>

Source§

impl<T> AsyncSliceReader for Box<T>

Source§

async fn read_at(&mut self, offset: u64, len: usize) -> Result<Bytes, Error>

Source§

async fn size(&mut self) -> Result<u64, Error>

Implementors§