pub struct DiffEngine;Expand description
Engine for generating and applying capability diffs
Implementations§
Source§impl DiffEngine
impl DiffEngine
Sourcepub fn diff(old: &CapabilitySet, new: &CapabilitySet) -> Vec<DiffOp>
pub fn diff(old: &CapabilitySet, new: &CapabilitySet) -> Vec<DiffOp>
Generate diff operations between old and new capability sets
Sourcepub fn apply(
base: &CapabilitySet,
diff: &CapabilityDiff,
strict: bool,
) -> Result<CapabilitySet, DiffError>
👎Deprecated since 0.10.0: version-naive — use apply_with_version to enforce the base_version check; this entry point is retained only for hand-built diffs in unit tests
pub fn apply( base: &CapabilitySet, diff: &CapabilityDiff, strict: bool, ) -> Result<CapabilitySet, DiffError>
version-naive — use apply_with_version to enforce the base_version check; this entry point is retained only for hand-built diffs in unit tests
Apply diff operations to a capability set, ignoring
diff.base_version.
Deprecated: production callers MUST use
Self::apply_with_version so a stale base_version → new_version diff cannot silently roll receiver state
backward. The version-naive entry point is preserved only
for hand-built diffs in unit tests where no live version is
tracked. New non-test callsites should reach for
apply_with_version.
Returns the updated capability set or an error if
application fails. The strict parameter controls whether
missing items cause errors.
This function ignores diff.base_version entirely. A
receiver at v5 will happily accept an old base_version=2 → new_version=3 diff and silently roll state back, so
callers MUST gate via apply_with_version outside tests.
Sourcepub fn apply_with_version(
base: &CapabilitySet,
current_version: u64,
diff: &CapabilityDiff,
strict: bool,
) -> Result<CapabilitySet, DiffError>
pub fn apply_with_version( base: &CapabilitySet, current_version: u64, diff: &CapabilityDiff, strict: bool, ) -> Result<CapabilitySet, DiffError>
Apply diff operations to a capability set, asserting that
the diff was generated against current_version (the version
the caller has authoritative state for).
Returns DiffError::VersionMismatch when
current_version != diff.base_version — i.e. the diff is
stale (older than what we hold) or out-of-order (newer than
what we have a base for). This is the correct contract for
any production caller; Self::apply is reserved for
version-naive contexts (tests, hand-built diffs, etc.).
The version-checked counterpart to apply, which is
version-naive and silently accepts stale diffs.
Sourcepub fn validate_chain(diffs: &[CapabilityDiff]) -> bool
pub fn validate_chain(diffs: &[CapabilityDiff]) -> bool
Validate that a chain of diffs is consistent
Checks that version numbers are sequential and base versions match.
Each diff is required to satisfy curr.new_version > curr.base_version AND
prev.new_version == curr.base_version between adjacent
diffs. The within-diff new_version > base_version invariant
is load-bearing — without it a peer could ship
base_version=5, new_version=3 (a “rollback while applying
ops”) and validation would accept it. Combined with the
version-naive Self::apply, a receiver could advance
state forward while its tracked version went backward.
Sourcepub fn compact(
base: &CapabilitySet,
diffs: &[CapabilityDiff],
) -> Option<CapabilityDiff>
pub fn compact( base: &CapabilitySet, diffs: &[CapabilityDiff], ) -> Option<CapabilityDiff>
Compact a chain of diffs into a single diff
This is useful for reducing storage/bandwidth when many small diffs accumulate.
Sourcepub fn bandwidth_savings(
diff: &CapabilityDiff,
full: &CapabilitySet,
) -> (usize, usize, f64)
pub fn bandwidth_savings( diff: &CapabilityDiff, full: &CapabilitySet, ) -> (usize, usize, f64)
Estimate bandwidth savings of using diff vs full announcement
Returns (diff_size, full_size, savings_percent)