Skip to main content

Source

Trait Source 

Source
pub trait Source {
    // Required methods
    fn len(&self) -> u64;
    fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Random-access bytes a document is read from.

Core crates never open files or sockets themselves (docs/PLAN.md §2, “No ambient I/O”); the caller hands them a Source backed by memory, a file, or anything else that can serve ranges.

Required Methods§

Source

fn len(&self) -> u64

Total length in bytes.

Source

fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>

Copies bytes starting at offset into buf and returns how many were copied. Fewer than buf.len() means the end of the source was reached; an offset at or past the end copies nothing.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the source holds no bytes.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Source for Vec<u8>

Source§

fn len(&self) -> u64

Source§

fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>

Source§

impl Source for [u8]

Source§

fn len(&self) -> u64

Source§

fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>

Source§

impl<S> Source for &S
where S: Source + ?Sized,

Source§

fn len(&self) -> u64

Source§

fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize, SourceError>

Implementors§