Skip to main content

ByteSource

Trait ByteSource 

Source
pub trait ByteSource:
    Send
    + Sync
    + Debug {
    // Required methods
    fn path(&self) -> &str;
    fn len(&self) -> Result<u64>;
    fn read_at(&self, offset: u64, len: usize) -> Result<Bytes>;

    // Provided methods
    fn is_empty(&self) -> Result<bool> { ... }
    fn read_exact_at(&self, offset: u64, len: usize) -> Result<Bytes> { ... }
    fn read_to_end(&self, offset: u64) -> Result<Bytes> { ... }
    fn prefetch(&self, _ranges: &[Range<u64>]) { ... }
    fn close(&self) { ... }
}
Expand description

A random-access source of bytes.

Send + Sync and read by offset, so the readers hand &dyn ByteSource to every worker rather than checking a handle out of a pool.

Debug is a supertrait so that the readers, which hold an Arc<dyn ByteSource>, can derive it — and so a source turns up legibly in a failed assertion rather than as an opaque pointer.

Required Methods§

Source

fn path(&self) -> &str

Path or URL this reads, for error messages.

Source

fn len(&self) -> Result<u64>

Total length in bytes.

Source

fn read_at(&self, offset: u64, len: usize) -> Result<Bytes>

Read up to len bytes at offset, returning fewer at end of file.

Provided Methods§

Source

fn is_empty(&self) -> Result<bool>

Source

fn read_exact_at(&self, offset: u64, len: usize) -> Result<Bytes>

Read exactly len bytes at offset; a short read is Error::Corrupt.

Source

fn read_to_end(&self, offset: u64) -> Result<Bytes>

Read from offset to end of file.

Source

fn prefetch(&self, _ranges: &[Range<u64>])

Announce ranges that are about to be read, so a source that can fetch them together does. A no-op unless overridden.

This is where read-ahead lives: the R-tree walk knows every leaf it is about to visit before it visits any of them, and over HTTP that knowledge is worth a multi-range request.

Source

fn close(&self)

Release the underlying handle. Idempotent; reads after it fail with Error::Closed.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: ByteSource + ?Sized> ByteSource for Arc<T>

Source§

fn path(&self) -> &str

Source§

fn len(&self) -> Result<u64>

Source§

fn read_at(&self, offset: u64, len: usize) -> Result<Bytes>

Source§

fn prefetch(&self, ranges: &[Range<u64>])

Source§

fn close(&self)

Implementors§