3 releases (breaking)

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

#780 in Rust patterns

Download history 312/week @ 2025-02-15 99/week @ 2025-02-22 111/week @ 2025-03-01 156/week @ 2025-03-08 128/week @ 2025-03-15 102/week @ 2025-03-22 82/week @ 2025-03-29 50/week @ 2025-04-05

394 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

~94KB