Skip to main content

Crate deltapatcher

Crate deltapatcher 

Source
Expand description

A library for computing, composing, and applying deltas between states.

§Core Traits

  • Patch<D> — implemented by types that can apply a delta D to mutate their state in-place.
  • Diff<D> — implemented by types that can produce a delta D relative to an initial state (requires Patch<D>).
  • Delta — implemented by the delta type itself; the key operation is aggregate, which composes two consecutive deltas into one. An aggregated A → C delta lets you reproduce the final state without ever materialising the intermediate B.

§Built-in Implementations

TypeDeltaNotes
Vec<T>, [T], [T; N]SliceDelta<T>LCS-based splice diff
u8, i8, … u64, i64ArithmeticDelta<T>Wrapping addition; any type implementing WrappingArithmetic gets this for free

§Macros

When the macros feature is enabled, procedural macros auto-generate delta types and trait implementations for your custom structs and enums:

  • #[derive(Diff)] — derives both Diff and Patch for full bidirectional diffing and patching.
  • #[derive(Patch)] — derives only Patch (skipping diff generation), ideal for client-side state receivers or read-only replicas.

§Timelines

Timeline<D, M> stores an ordered sequence of Commit<D, M> values and supports aggregate queries, range merging, and state replay.

StateCachedTimeline<T, D, M> adds periodic state snapshots at a configurable interval, reducing arbitrary state-retrieval and delta-query cost from O(N) to O(interval). It also supports efficient bidirectional seeking via delta_between — the same call handles both forward and inverse (backward) deltas.

§Utilities

ChangeBucket<T> holds “old” and “new” copies of a value. Mutate new freely through DerefMut, then call pop() to extract the accumulated delta and reset the baseline — handy for pipelines that only want to emit a commit when something actually changed.

§Feature Flags

FeatureDescription
stdEnabled by default, adding a dependency on the standard library. Remove this feature for no_std environments.
allocEnabled by default, linking the alloc crate. This is required for timelines and allocating deltas such as SliceDelta.
macrosEnables proc-macros to auto-generate many of the trait implementations from this crate.
serdeDerives serde::Serialize/Deserialize on all delta and timeline types

Re-exports§

pub use deltapatcher_macros as macros;macros

Modules§

delta
timelinealloc
util

Traits§

Delta
A value that encodes the change between two states and can be composed with other deltas of the same type.
Diff
Trait for types that can compute the difference (delta) relative to another state of the same type.
Patch
Trait for types that can be updated in-place by applying a delta.

Derive Macros§

Diffmacros
Derives Diff and Patch for a struct or enum, generating a corresponding Delta type.
Patchmacros
Derives only Patch for a struct or enum, generating a corresponding Delta type.