#[derive(GetterMut)]
{
// Attributes available to this derive:
#[get_mut]
}
Expand description
A procedural macro that automatically generates mutable getter methods for struct and enum fields.
This macro derives mutable getter methods that provide mutable references to field values, allowing modification of the struct’s fields while maintaining proper borrowing semantics.
§Supported Attributes
#[get_mut(pub)]- Generates a public mutable getter#[get_mut(pub(crate))]- Generates a crate-visible mutable getter#[get_mut(pub(super))]- Generates a mutable getter visible to parent module#[get_mut(private)]- Generates a private mutable getter
§Example
use lombok_macros::*;
#[derive(GetterMut, Clone)]
struct StructWithLifetimes<'a, 'b, T: Clone> {
#[get_mut(pub(crate))]
list: Vec<String>,
#[get_mut(pub(crate))]
optional_lifetime_a: Option<&'a T>,
optional_lifetime_b: Option<&'b str>,
}
let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
let mut struct_with_lifetimes: StructWithLifetimes<usize> = StructWithLifetimes {
list: list.clone(),
optional_lifetime_a: None,
optional_lifetime_b: None,
};
let mut list_reference: &mut Vec<String> = struct_with_lifetimes.get_mut_list();
list_reference.push("new_item".to_string());
assert_eq!(*list_reference, vec!["hello".to_string(), "world".to_string(), "new_item".to_string()]);