patchable_macros

Derive Macro Patchable

Source
#[derive(Patchable)]
{
    // Attributes available to this derive:
    #[patch]
}
Expand description

Creates a patch struct and implements Patchable.

#[derive(Patchable)]
struct MyStruct {
    foo: String,
    bar: i32
}

would generate

pub struct MyStructPatch {
    pub foo: Option<String>,
    pub bar: Option<String>
}
 
impl Patchable<MyStructPatch> for MyStruct {
    // skipped for brevity
}

You can also specify using the #[patch(PatchType)] attribute to change both the name of the generated struct, and the type of the replacement field in the generate struct. This works as long as the field type implements Patchable<PatchType>.

This allows for nesting of patches.

#[derive(Patchable)]
#[patch(MyPatch)]
struct MyStruct {
    foo: String,
    #[patch(BarPatch)]
    bar: Bar,
}
 
#[derive(Patchable)]
struct Bar {
    foobar: i32,
}

would generate

struct MyPatch {
    foo: Option<String>,
    bar: BarPatch,
}
 
struct BarPatch {
    foobar: Option<i32>,
}
// Patchable impls...