pub trait AsyncSliceReader {
    type ReadAtFuture<'a>: Future<Output = Result<Bytes, Error>> + 'a
       where Self: 'a;
    type LenFuture<'a>: Future<Output = Result<u64, Error>> + 'a
       where Self: 'a;

    // Required methods
    fn read_at(&mut self, offset: u64, len: usize) -> Self::ReadAtFuture<'_>;
    fn len(&mut self) -> Self::LenFuture<'_>;
}
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 Associated Types§

source

type ReadAtFuture<'a>: Future<Output = Result<Bytes, Error>> + 'a where Self: 'a

The future returned by read_at

source

type LenFuture<'a>: Future<Output = Result<u64, Error>> + 'a where Self: 'a

The future returned by len

Required Methods§

source

fn read_at(&mut self, offset: u64, len: usize) -> Self::ReadAtFuture<'_>

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 len(&mut self) -> Self::LenFuture<'_>

Get the length of the resource

Implementations on Foreign Types§

source§

impl AsyncSliceReader for Bytes

§

type ReadAtFuture<'a> = Ready<Result<Bytes, Error>>

source§

fn read_at( &mut self, offset: u64, len: usize ) -> <Bytes as AsyncSliceReader>::ReadAtFuture<'_>

§

type LenFuture<'a> = Ready<Result<u64, Error>>

source§

fn len(&mut self) -> <Bytes as AsyncSliceReader>::LenFuture<'_>

source§

impl<'b, T> AsyncSliceReader for &'b mut Twhere T: AsyncSliceReader,

§

type ReadAtFuture<'a> = <T as AsyncSliceReader>::ReadAtFuture<'a> where 'b: 'a, T: 'a

§

type LenFuture<'a> = <T as AsyncSliceReader>::LenFuture<'a> where 'b: 'a, T: 'a

source§

fn read_at( &mut self, offset: u64, len: usize ) -> <&'b mut T as AsyncSliceReader>::ReadAtFuture<'_>

source§

fn len(&mut self) -> <&'b mut T as AsyncSliceReader>::LenFuture<'_>

source§

impl<T> AsyncSliceReader for Box<T, Global>where T: AsyncSliceReader,

§

type ReadAtFuture<'a> = <T as AsyncSliceReader>::ReadAtFuture<'a> where T: 'a

§

type LenFuture<'a> = <T as AsyncSliceReader>::LenFuture<'a> where T: 'a

source§

fn read_at( &mut self, offset: u64, len: usize ) -> <Box<T, Global> as AsyncSliceReader>::ReadAtFuture<'_>

source§

fn len(&mut self) -> <Box<T, Global> as AsyncSliceReader>::LenFuture<'_>

source§

impl<L, R> AsyncSliceReader for Either<L, R>where L: AsyncSliceReader + 'static, R: AsyncSliceReader + 'static,

§

type ReadAtFuture<'a> = Either<<L as AsyncSliceReader>::ReadAtFuture<'a>, <R as AsyncSliceReader>::ReadAtFuture<'a>>

source§

fn read_at( &mut self, offset: u64, len: usize ) -> <Either<L, R> as AsyncSliceReader>::ReadAtFuture<'_>

§

type LenFuture<'a> = Either<<L as AsyncSliceReader>::LenFuture<'a>, <R as AsyncSliceReader>::LenFuture<'a>>

source§

fn len(&mut self) -> <Either<L, R> as AsyncSliceReader>::LenFuture<'_>

source§

impl AsyncSliceReader for BytesMut

§

type ReadAtFuture<'a> = Ready<Result<Bytes, Error>>

source§

fn read_at( &mut self, offset: u64, len: usize ) -> <BytesMut as AsyncSliceReader>::ReadAtFuture<'_>

§

type LenFuture<'a> = Ready<Result<u64, Error>>

source§

fn len(&mut self) -> <BytesMut as AsyncSliceReader>::LenFuture<'_>

Implementors§