Skip to main content

ByteSource

Trait ByteSource 

Source
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

TypeI/O modelUse when
SliceBackendZero-copy &[u8] borrowBytes already in memory
MmapBackendZero-copy mmap, OS pages on demandLocal files of any size
(future) ReadBackend::StreamedSliding window over Read + SeekHTTP 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§

Source

fn len(&self) -> usize

Total length of the source in bytes.

Source

fn byte_at(&self, offset: usize) -> Option<u8>

Return the byte at absolute offset, or None if out of bounds.

Source

fn slice_at(&self, offset: usize, len: usize) -> Option<&[u8]>

Return a slice of len bytes starting at absolute offset, or None if the range is not fully available.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the source is empty.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§