purpurea 0.1.0

Attribute based accessor/updater/mutator/constructor generation.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented5 out of 5 items with examples
  • Size
  • Source code size: 21.63 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 353.9 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bsoptei

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