Skip to main content

DeltaBaseSource

Trait DeltaBaseSource 

Source
pub trait DeltaBaseSource {
    const VERIFIED: bool = false;

    // Required method
    fn base(&mut self, id: &Hash) -> Result<Option<Vec<u8>>, PackError>;

    // Provided method
    fn base_with_admission(
        &mut self,
        id: &Hash,
        admit: impl FnOnce(usize) -> Result<(), PackError>,
    ) -> Result<Option<Vec<u8>>, PackError> { ... }
}
Expand description

Where a delta’s external base — one that is not an earlier entry of the same pack — may come from.

SPEC-PACKFILE §3.2’s “destination object store” is the implementor: the local ObjectStore on a client, and on a server the pushing repository’s own membership. A server MUST NOT back this with a global content store or another repository’s objects: whether a delta resolves would then reveal that some other repository holds the base (PRD §6.5 repository isolation, no existence oracles).

The seam is generic, never dyn: PackReader::read instantiates it with &ObjectStore so the hot unpack path stays monomorphic.

Provided Associated Constants§

Source

const VERIFIED: bool = false

Whether Self::base returns bytes already verified to be the object named by the requested id (the store’s read verifies).

When false (the default), the decoder deserializes the bytes and re-derives the id itself; anything that is not a storable canonical object with exactly the requested id is treated as absent (PackError::DeltaBaseMissing), so an untrusted source can never smuggle a different object in as a base. Set it to true only when base itself guarantees that identity, as ObjectStore::read does; the decoder then skips the re-derive.

Required Methods§

Source

fn base(&mut self, id: &Hash) -> Result<Option<Vec<u8>>, PackError>

Canonical object bytes for id, or None when this source may not provide it. “Not permitted” and “does not exist” MUST both be None: the decoder reports them identically, by design.

§Errors

A source failure (I/O, backend error) that is not an answer about id. It aborts the decode.

Provided Methods§

Source

fn base_with_admission( &mut self, id: &Hash, admit: impl FnOnce(usize) -> Result<(), PackError>, ) -> Result<Option<Vec<u8>>, PackError>

Fetch with allocation admission. The default charges after base returns; sources that know the length first should override this to call admit before allocating, as &ObjectStore does. Before returning Some(bytes), every override must successfully invoke admit exactly once with bytes.len() and propagate its error.

§Errors

Returns a source failure or the error from admit.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§