morphix
A Rust library for observing and serializing changes.
Installation
Add this to your Cargo.toml:
[]
= { = "0.1", = ["json"] }
Basic Usage
use Serialize;
use json;
use ;
// 1. Define any data structure with `#[derive(Observe)]`.
let mut foo = Foo ;
// 2. Use `observe!` to mutate data and track changes.
let change = observe!.unwrap;
// 3. Inspect the changes.
assert_eq!;
// 4. The original data structure is also mutated.
assert_eq!;
Change Types
morphix recognizes three types of changes:
Replace
The most general change type, used for any mutation that replaces a value:
person.age = 35; // Replace at .age
person.name = "Bob".into; // Replace at .name
Append
Optimized for appending to strings and vectors:
person.name.push_str; // Append to .name
person.hobbies.push; // Append to .hobbies
Batch
Multiple changes combined into a single operation.
Features
derive(default): Enables the Observe derive macrojson: Includes JSON serialization support viaserde_jsonyaml: Includes YAML serialization support viaserde_yml