Trait bao_tree::io::fsm::AsyncSliceReader
source · 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§
Required Methods§
sourcefn read_at(&mut self, offset: u64, len: usize) -> Self::ReadAtFuture<'_>
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.