umili

Crates.ioumili
lib.rsumili
version0.2.2
created_at2025-02-15 17:36:08.27806+00
updated_at2025-09-25 14:42:47.969636+00
descriptionMutate and observe Rust data structures
homepage
repositoryhttps://github.com/shigma/umili
max_upload_size
id1556981
size27,159
Shigma (shigma)

documentation

https://docs.rs/umili

README

umili

Mutate and observe Rust data structures.

Basic Usage

use serde::{Serialize, Deserialize};
use umili::{observe, Change, Observe};

// 1. Define any data structure with `#[derive(Observe)]`.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Observe)]
pub struct Foo {
    pub bar: Bar,
    pub qux: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Observe)]
pub struct Bar {
    pub baz: i32,
}

let mut foo = Foo { bar: Bar { baz: 42 }, qux: "hello".to_string() };

// 2. Use `observe!` to mutate and observe the data structure.
let diff = observe!(|mut foo| {
    foo.bar.baz += 1;
    foo.qux += " world";
}).unwrap();

// 3. See the changes.
assert_eq!(diff, vec![
    Change::set("bar/baz", 43).unwrap(),
    Change::append("qux", " world").unwrap(),
]);

assert_eq!(foo, Foo { bar: Bar { baz: 43 }, qux: "hello world".to_string() });
Commit count: 22

cargo fmt