pub trait ByteSource: Debug {
// Required methods
fn len(&self) -> usize;
fn byte_at(&self, offset: usize) -> Option<u8>;
fn slice_at(&self, offset: usize, len: usize) -> Option<&[u8]>;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
A legacy source of bytes addressable at arbitrary offsets.
§Implementors
| Type | I/O model | Use when |
|---|---|---|
SliceBackend | Zero-copy &[u8] borrow | Bytes already in memory |
MmapBackend | Zero-copy mmap, OS pages on demand | Local files of any size |
(future) ReadBackend::Streamed | Sliding window over Read + Seek | HTTP range requests, pipes |
§Future: Read + Seek sources
A Streamed variant wrapping a Box<dyn ReadAndSeek> or similar
is the natural extension. It would maintain an internal sliding window:
reads that fall within the current window return &[u8] slices;
reads beyond it trigger a window shift via Seek::seek + Read::read_exact.
Callers that need this today can prototype by reading the file on
their own terms and using ReadBackend::Slice.
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".