3 releases (breaking)

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

#1633 in Rust patterns

Download history 290/week @ 2025-02-14 96/week @ 2025-02-21 115/week @ 2025-02-28 145/week @ 2025-03-07 142/week @ 2025-03-14

519 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