Crate decorators[−][src]
Expand description
A Procedural Macro for Decorators
The Decorator macro generates a decorator method for each marked field. A field can be marked with the #[dec]
field in front.
Example
#[derive(Decorator)] struct Widget { #[dec] width: u32, #[dec] height: u32, }
Generates into:
struct Widget { width: u32, height: u32, } impl Widget { pub fn width(self, width: u32) -> Self { Self { width, ..self } } pub fn height(self, height: u32) -> Self { Self { height, ..self } } }
Which can be used like:
let w = some_widget.width(10).height(20); assert_eq!(w, Widget {width: 10, height: 20});
Derive Macros
Decorator | A macro to generate a decorator method for each marked field.
A field can be marked with the |