Skip to main content

ByteSource

Trait ByteSource 

Source
pub trait ByteSource:
    Send
    + Sync
    + Debug {
    // Required methods
    fn size(&self) -> Result<u64>;
    fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize>;
    fn name(&self) -> String;

    // Provided methods
    fn read_exact_at(&self, offset: u64, buf: &mut [u8]) -> Result<()> { ... }
    fn read_range(&self, offset: u64, len: usize) -> Result<SharedBytes> { ... }
    fn local_path(&self) -> Option<&Path> { ... }
}
Expand description

Random-access bytes of one file.

Only size, read_at and name are required. size is asked again whenever a reader wants the length, so a source over a file that is still being written reports its current size.

Required Methods§

Source

fn size(&self) -> Result<u64>

Current length in bytes.

Source

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

Read up to buf.len() bytes at offset; return how many were read (0 at or past the end). Like std::io::Read::read, a short read is allowed anywhere.

Source

fn name(&self) -> String

A name for messages: the path of a local file, the name a host gave its buffer.

Provided Methods§

Source

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

Fill buf from offset, or fail with UnexpectedEof if the source ends first.

Source

fn read_range(&self, offset: u64, len: usize) -> Result<SharedBytes>

Up to len bytes at offset (fewer at the end of the source). In-memory sources return a view of their buffer without copying; the default reads into a new buffer.

Source

fn local_path(&self) -> Option<&Path>

The file on the local disk this source reads, if it is one.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§