pub trait AsyncSliceReader: Sized {
    type ReadFuture: Future<Output = (Self, BytesMut, Result<()>)> + Send;
    type LenFuture: Future<Output = (Self, Result<u64>)> + Send;

    // Required methods
    fn read_at(self, offset: u64, buf: BytesMut) -> Self::ReadFuture;
    fn len(self) -> Self::LenFuture;
}
Expand description

A reader that can read a slice at a specified offset

For a file, this will be implemented by seeking to the offset and then reading the data. For other types of storage, seeking is not necessary. E.g. a Bytes or a memory mapped slice already allows random access.

For external storage such as S3/R2, this might be implemented in terms of async http requests.

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 ReadFuture: Future<Output = (Self, BytesMut, Result<()>)> + Send

source

type LenFuture: Future<Output = (Self, Result<u64>)> + Send

Required Methods§

source

fn read_at(self, offset: u64, buf: BytesMut) -> Self::ReadFuture

Read the entire buffer at the given position.

Will fail if the file is smaller than offset + buf.len()

source

fn len(self) -> Self::LenFuture

Get the length of the file

Implementors§

source§

impl<R: Read + Seek + Unpin + Send + 'static> AsyncSliceReader for SyncIoAdapter<R>

source§

impl<R: AsyncRead + AsyncSeek + Unpin + Send + 'static> AsyncSliceReader for R

§

type ReadFuture = Pin<Box<dyn Future<Output = (R, BytesMut, Result<(), Error>)> + Send + 'static, Global>>

§

type LenFuture = Pin<Box<dyn Future<Output = (R, Result<u64, Error>)> + Send + 'static, Global>>