Skip to main content

ByteSource

Trait ByteSource 

Source
pub trait ByteSource {
    // Required methods
    fn read_range(
        &self,
        offset: u64,
        length: u64,
    ) -> impl Future<Output = Result<Vec<u8>, CopcError>>;
    fn size(&self) -> impl Future<Output = Result<Option<u64>, CopcError>>;

    // Provided method
    fn read_ranges(
        &self,
        ranges: &[(u64, u64)],
    ) -> impl Future<Output = Result<Vec<Vec<u8>>, CopcError>> { ... }
}
Expand description

Async random-access byte source.

Implementations can back this with HTTP range requests, local file I/O, in-memory buffers, or any other random-access mechanism.

All methods return non-Send futures for WASM compatibility.

Required Methods§

Source

fn read_range( &self, offset: u64, length: u64, ) -> impl Future<Output = Result<Vec<u8>, CopcError>>

Read length bytes starting at offset.

Source

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

Total size of the source in bytes, if known.

Provided Methods§

Source

fn read_ranges( &self, ranges: &[(u64, u64)], ) -> impl Future<Output = Result<Vec<Vec<u8>>, CopcError>>

Read multiple ranges in one logical operation.

The default implementation issues sequential reads. HTTP implementations should override to issue parallel requests.

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 ByteSource for &[u8]

Byte source over a shared slice reference.

Source§

async fn read_range( &self, offset: u64, length: u64, ) -> Result<Vec<u8>, CopcError>

Source§

async fn size(&self) -> Result<Option<u64>, CopcError>

Source§

impl ByteSource for Vec<u8>

In-memory byte source, useful for testing and when data is already loaded.

Source§

async fn read_range( &self, offset: u64, length: u64, ) -> Result<Vec<u8>, CopcError>

Source§

async fn size(&self) -> Result<Option<u64>, CopcError>

Implementors§