Skip to main content

ModuleReader

Trait ModuleReader 

Source
pub trait ModuleReader: Send + Sync {
    // Required methods
    fn len(&self) -> u64;
    fn read_at<'life0, 'async_trait>(
        &'life0 self,
        offset: u64,
        len: u64,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, DownloadError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

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

Random-access read over the module bytes a pull has staged — the seam the anchor gate sees INSTEAD of a &[u8] of the whole module (#1610).

A &[u8] parameter forced the puller to hold the entire module in RAM before it could ask the one question that decides the pull, so peak RSS was the module size and a small host simply could not reshare a large capsule. Behind this trait the same gate reads the staging area on demand, so peak RSS is one chunk.

§What an implementation MUST guarantee

Every byte this reader returns is already chunk-hash-verified against the descriptor, and the readable window is exactly the total_size the whole-module-hash gate has already accepted — the gate never sees an unverified or out-of-window byte (StagedModuleReader is this crate’s implementation and enforces both).

Required Methods§

Source

fn len(&self) -> u64

The module’s verified length in bytes. Reads are clamped to [0, len()).

Source

fn read_at<'life0, 'async_trait>( &'life0 self, offset: u64, len: u64, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, DownloadError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read the [offset, offset + len) window of the module.

§Errors

DownloadError::Sink when the window falls outside the module or the staged bytes cannot be read back / no longer match the descriptor’s chunk hashes. A read error is never “zeroes”: the caller MUST treat it as a failure to verify, never as absent content.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the module is empty — present because clippy requires it beside len; a real .dig module is never empty.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§