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§
Provided Methods§
fn is_empty(&self) -> Result<bool>
Sourcefn read_exact_at(&self, offset: u64, len: usize) -> Result<Bytes>
fn read_exact_at(&self, offset: u64, len: usize) -> Result<Bytes>
Read exactly len bytes at offset; a short read is Error::Corrupt.
Sourcefn read_to_end(&self, offset: u64) -> Result<Bytes>
fn read_to_end(&self, offset: u64) -> Result<Bytes>
Read from offset to end of file.
Sourcefn prefetch(&self, _ranges: &[Range<u64>])
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.
Sourcefn close(&self)
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".