structdiff

A lightweight, zero-dependency struct diffing library which allows changed fields to be collected and applied. Derive Difference on a struct, then use the StructDiff trait to make and apply diffs. Supports optional serialization of the generated diff types with serde or nanoserde for ease of use.

Crates.io

Example:

```rust use structdiff::{Difference, StructDiff};

[derive(Debug, PartialEq, Clone, Difference)]

struct Example { field1: f64, #[difference(skip)] field2: Vec, #[difference(collectionstrategy="unorderedarray_like")] field3: BTreeSet, }

let first = Example { field1: 0.0, field2: vec![], field3: vec![1, 2, 3].into_iter().collect(), };

let second = Example { field1: 3.14, field2: vec![1], field3: vec![2, 3, 4].into_iter().collect(), };

let diffs = first.diff(&second); // diffs is now a Vec of differences between the two instances, // with length equal to number of changed/unskipped fields assert_eq!(diffs.len(), 2);

let diffed = first.apply(diffs); // diffed is now equal to second, except for skipped field asserteq!(diffed.field1, second.field1); asserteq!(&diffed.field3, &second.field3); assert_ne!(diffed, second); ```

For more examples take a look at integration tests

Derive macro attributes

Optional features

Development status

This is being used actively for my own projects, although it's mostly working now. PRs will be accepted for either more tests or functionality.