Skip to main content

ByteSource

Trait ByteSource 

Source
pub trait ByteSource: Debug {
    // Required methods
    fn len(&self) -> u64;
    fn read_at(
        &self,
        offset: u64,
        target: &mut [u8],
    ) -> Result<(), BackendError>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn as_contiguous(&self) -> Option<&[u8]> { ... }
}
Expand description

A bounded byte source that may be physically segmented.

Transport adapters can implement this trait over validated descriptor-backed regions so providers can read directly into final program or buffer storage without first coalescing the complete payload. Every range fully contained in 0..len() must be readable for the duration of the backend call. The optional contiguous view preserves the single-slice fast path.

Required Methods§

Source

fn len(&self) -> u64

Stable logical length of this source.

Source

fn read_at(&self, offset: u64, target: &mut [u8]) -> Result<(), BackendError>

Fill target from the exact logical range beginning at offset.

Provided Methods§

Source

fn is_empty(&self) -> bool

Source

fn as_contiguous(&self) -> Option<&[u8]>

Borrow the complete logical source when it is one contiguous region.

A returned slice has length Self::len and contains the same bytes as read_at.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl ByteSource for [u8]

Source§

fn len(&self) -> u64

Source§

fn read_at(&self, offset: u64, target: &mut [u8]) -> Result<(), BackendError>

Source§

fn as_contiguous(&self) -> Option<&[u8]>

Source§

impl<const N: usize> ByteSource for [u8; N]

Source§

fn len(&self) -> u64

Source§

fn read_at(&self, offset: u64, target: &mut [u8]) -> Result<(), BackendError>

Source§

fn as_contiguous(&self) -> Option<&[u8]>

Implementors§