Crate purpurea[][src]

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.

Example

mod examples {
    use purpurea::*;
     
    #[accessors(email)]
    #[updaters(email)]
    #[default_constructor]
    pub struct User {
        email: String,
        account_number: usize
    }
}
     
use examples::*;

let john_doe = User::new("john_doe@example.com", 45275);
let new_email = "john_doe@example2.com";
let john_doe2 = john_doe.with_email(new_email.to_owned());

assert_eq!(new_email, john_doe2.email());

Attribute Macros

accessors

Generates accessor methods with names corresponding to those of the the struct’s fields.

default_constructor

Generates a constructor method called new.

mutators

Generates mutator methods with names corresponding to those of the the struct’s fields, with a prefix of set_.

updaters

Generates updater methods with names corresponding to those of the the struct’s fields, with a prefix of with_. You won’t have to declare your values mutable.