3 releases (breaking)

new 0.3.0 Feb 18, 2025
0.2.0 Feb 17, 2025
0.1.0 Feb 16, 2025

#682 in Rust patterns

Download history 131/week @ 2025-02-12

131 downloads per month

MIT/Apache

11KB
75 lines

Patched

github Latest version Documentation MIT Apache

A macro that generates patch struct.

use patched::Patch;

#[derive(Patch)]
struct Foo {
    a: u8,
    b: String,
}

// Will generates

struct FooPatch {
    a: Option<u8>
    b: Option<String>,
}

impl Default for FooPatch {
    /* ... */
}

impl Patch<FooPatch> for Foo {
    /* ... */
}

Usage example:

let mut value = Foo {
    a: 10,
    b: String::from("Hello");
}

value.patch(FooPatch {
    a: Some(99),
    ..Default::default()
});

assert_eq!(
    value,
    Foo {
        a: 99,
        b: String::from("Hello");
    }
);

Dependencies

~97KB