morphix
A Rust library for observing and serializing mutations.
Installation
Add this to your Cargo.toml:
[]
= { = "0.3", = ["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 mutations.
let mutation = observe!.unwrap;
// 3. Inspect the mutations.
assert_eq!;
// 4. The original data structure is also mutated.
assert_eq!;
Mutation Types
Morphix recognizes three types of mutations:
Replace
The most general mutation type, used for any mutation that replaces a value:
foo.a.b = 1; // Replace at .a.b
foo.num *= 2; // Replace at .num
foo.vec.clear; // Replace at .vec
Append
Optimized for appending to strings and vectors:
foo.a.b += "text"; // Append to .a.b
foo.a.b.push_str; // Append to .a.b
foo.vec.push; // Append to .vec
foo.vec.extend; // Append to .vec
Batch
Multiple mutations 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