Skip to main content

ByteSource

Trait ByteSource 

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

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

Re-export framework services (HTTP, URI, etc.) from the dedicated services crate. Random-access source of bytes the app is willing to serve.

Implementations are Send + Sync so the server can read from a worker thread. A non-seekable backing store (e.g. a streamed content:// document) should spool internally so read_at still answers arbitrary offsets.

Required Methods§

Source

fn len(&self) -> Option<u64>

Total length in bytes, if known. None disables Range responses.

Source

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

Reads up to buf.len() bytes starting at offset; returns the number read (0 at end of source).

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the source is empty. Provided for the clippy::len_without_is_empty lint.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§