pub trait ByteSource: Send + Sync {
// Required methods
fn len(&self) -> u64;
fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn as_slice(&self) -> Option<&[u8]> { ... }
}Expand description
Random-access input bytes: in memory, memory-mapped, a browser Blob, an HTTP range cache.
Synchronous by design (the core has no async runtime): a source whose bytes have not
arrived yet answers SourceError::Pending, and the shell fetches them and retries.
In-memory sources return their bytes from ByteSource::as_slice, which lets the
parser work on them in place.
A source without as_slice is read in aligned 64 KiB windows (and small probes for xref
entry checks); read_at may return fewer bytes than asked for and is called again for the
rest. A SourceError::Pending is reported to the caller as
Error::DataPending with the range the source gave.
Core implementations: Vec<u8> (moved in), Arc<[u8]> (shared), &'static [u8].
Platform sources (mmap, Blob, OPFS) live in edge crates.
Added in 0.2.0.
Required Methods§
Sourcefn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>
fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>
Fills buf from offset; returns the bytes read (short only at the end of input).
§Errors
SourceError::Pending when the range is not available yet, SourceError::Failed
when it cannot be read.
Added in 0.2.0.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".