#[deltastruct]Expand description
An attribute macro applied to mods. Will generate a Delta and it’s DeltaStruct<_> implementation.
Applied to a mod. Expects the mod to have a struct with the same name
and an implementation. Currently at least one field is expected in the struct
definition and at least one method is expected in the implementation. This macro
will generate an enum with the same name as the mod with Delta appended,
and an implementation impl DeltaStruct<FooDelta> for Foo.
The delta will have a tuple variant for each method defined for the struct
converted to camel case, and it’s tuple will be of the same type as the
argument list of it’s respective method (without &mut self). It will also
expose delta functions of it’s fields.
§Example:
#[deltastruct]
mod Foo {
struct Foo {
x : i32,
y : i32
}
impl Foo {
fn swap(&mut self) {
let tmp = self.x;
self.x = self.y;
self.y = tmp;
}
fn do_stuff(&mut self, n : f64) {
self.x = (n * (self.x as f64)) as i32;
}
}
}will generate:
enum FooDelta {
Swap(),
DoStuff(f64),
X(i32Delta),
Y(i32Delta),
}
impl DeltaStruct<FooDelta> for Foo {
fn apply(&mut self, delta : &FooDelta) {
/* ... */
}
}