#updater

macro purpurea

Attribute based accessor/updater/mutator/constructor generation

1 unstable release

0.1.0 Apr 2, 2021

#27 in #updater

MIT license

21KB
184 lines

purpurea

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());

lib.rs:

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());

Dependencies

~1.5MB
~37K SLoC