Skip to main content

with

Attribute Macro with 

Source
#[with]
Expand description

Adds a by-value builder method for a method that takes &mut self.

The generated method is named with_*, where * is the portion of the original method’s name after its first underscore.

§Example

#[derive(Default)]
struct Config {
    value: usize,
}

impl Config {
    #[mkutils_macros::with]
    fn set_value(&mut self, value: usize) {
        self.value = value;
    }
}

let config = Config::default().with_value(42);

std::assert_eq!(config.value, 42);