Expand description
A library for computing, composing, and applying deltas between states.
§Core Traits
Patch<D>— implemented by types that can apply a deltaDto mutate their state in-place.Diff<D>— implemented by types that can produce a deltaDrelative to an initial state (requiresPatch<D>).Delta— implemented by the delta type itself; the key operation isaggregate, which composes two consecutive deltas into one. An aggregatedA → Cdelta lets you reproduce the final state without ever materialising the intermediateB.
§Built-in Implementations
| Type | Delta | Notes |
|---|---|---|
Vec<T>, [T], [T; N] | SliceDelta<T> | LCS-based splice diff |
u8, i8, … u64, i64 | ArithmeticDelta<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 bothDiffandPatchfor full bidirectional diffing and patching.#[derive(Patch)]— derives onlyPatch(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
| Feature | Description |
|---|---|
std | Enabled by default, adding a dependency on the standard library. Remove this feature for no_std environments. |
alloc | Enabled by default, linking the alloc crate. This is required for timelines and allocating deltas such as SliceDelta. |
macros | Enables proc-macros to auto-generate many of the trait implementations from this crate. |
serde | Derives serde::Serialize/Deserialize on all delta and timeline types |
Re-exports§
pub use deltapatcher_macros as macros;macros
Modules§
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.