Skip to main content

AsyncSource

Trait AsyncSource 

Source
pub trait AsyncSource: Send {
    // Required methods
    fn read_at(
        &mut self,
        offset: u64,
        out: &mut [u8],
    ) -> impl Future<Output = Result<usize, BoxedError>> + Send;
    fn len(&mut self) -> impl Future<Output = Result<u64, BoxedError>> + Send;

    // Provided methods
    fn read_ranges(
        &mut self,
        reqs: &mut [(u64, &mut [u8])],
    ) -> impl Future<Output = Result<(), BoxedError>> + Send { ... }
    fn len_hint(&self) -> Option<u64> { ... }
}
Expand description

Where the async drivers get bytes: a socket, an HTTP body, an object store with range requests.

Required Methods§

Source

fn read_at( &mut self, offset: u64, out: &mut [u8], ) -> impl Future<Output = Result<usize, BoxedError>> + Send

Read up to out.len() bytes at offset into out and return the count. Like AsyncRead, a read may return fewer bytes than asked: whatever has arrived, so a decoder can start on it. Zero means the source ends at offset.

Source

fn len(&mut self) -> impl Future<Output = Result<u64, BoxedError>> + Send

Total length. Sequential sources can only answer once they reached the end; they return an error before that.

Provided Methods§

Source

fn read_ranges( &mut self, reqs: &mut [(u64, &mut [u8])], ) -> impl Future<Output = Result<(), BoxedError>> + Send

Fill each buffer from its offset. Sources that can serve ranges concurrently (HTTP/2, object stores) override this to overlap them; the default reads them one after another.

Source

fn len_hint(&self) -> Option<u64>

Total length if known without reading ahead.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§