This crate provides attribute based convenience method generation (accessor/updater/mutator/constructor) for structs with private fields.
The observed results achieved by the crate's attibute macros are somewhat similar to that of the @Getter
/@Setter
and the @RequiredArgsConstructor
/@AllArgsConstructor
annotations of Java library Lombok, with a Rust flavor.
``` mod examples { use purpurea::*;
#[accessors(email)]
#[updaters(email)]
#[default_constructor]
pub struct User {
email: String,
account_number: usize
}
}
use examples::*;
let johndoe = User::new("johndoe@example.com", 45275); let newemail = "johndoe@example2.com"; let johndoe2 = johndoe.withemail(newemail.to_owned());
asserteq!(newemail, john_doe2.email()); ```