Skip to main content

DiffEngine

Struct DiffEngine 

Source
pub struct DiffEngine;
Expand description

Engine for generating and applying capability diffs

Implementations§

Source§

impl DiffEngine

Source

pub fn diff(old: &CapabilitySet, new: &CapabilitySet) -> Vec<DiffOp>

Generate diff operations between old and new capability sets

Source

pub 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

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.

Source

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.

Source

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.

Source

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.

Source

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)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more