#regex #validation #json #build #logs #proc-macro #getter-setter

macro darth-rust

DarthRust is a Rust procedural macro library that aims to enhance developer productivity by auto-generating essential methods for struct manipulation. It provides a suite of macros that can be derived on any struct to equip it with a rich API for accessing and modifying fields, performing calculations, and handling input/output operations. With features like mutable and immutable getters, setters, JSON conversion methods, and custom printer functions for debugging, DarthRust streamlines the boilerplate code typically associated with struct management in Rust applications. It also includes unique methods for regex validation and range checking, further extending its utility. The library emphasizes ease of use, requiring only the addition of relevant crates and a simple derive attribute to unlock its full potential.

66 releases (30 stable)

new 4.3.0 Apr 30, 2024
3.0.8 Apr 9, 2024
2.1.0 Apr 3, 2024
1.1.0 Mar 23, 2024
0.2.5 Nov 26, 2023

#677 in Procedural macros

Download history 21/week @ 2024-01-18 49/week @ 2024-01-25 17/week @ 2024-02-01 84/week @ 2024-02-15 156/week @ 2024-02-22 102/week @ 2024-02-29 69/week @ 2024-03-07 495/week @ 2024-03-14 352/week @ 2024-03-21 323/week @ 2024-03-28 996/week @ 2024-04-04 1251/week @ 2024-04-11 170/week @ 2024-04-18 199/week @ 2024-04-25

2,769 downloads per month
Used in 8 crates

MIT license

55KB
1K SLoC

Darth Rust

About

DarthRust is a Rust procedural macro library that aims to enhance developer productivity by auto-generating essential methods for struct manipulation. It provides a suite of macros that can be derived on any struct to equip it with a rich API for accessing and modifying fields, performing calculations, and handling input/output operations. With features like mutable and immutable getters, setters, JSON conversion methods, and custom printer functions for debugging, DarthRust streamlines the boilerplate code typically associated with struct management in Rust applications. It also includes unique methods for regex validation and range checking, further extending its utility. The library emphasizes ease of use, requiring only the addition of relevant crates and a simple derive attribute to unlock its full potential.

Install, features = ["full"]

cargo add darth-rust
cargo add regex
cargo add colorful
cargo add serde
cargo add serde_json
cargo add chrono

Use

Examples

https://github.com/pas2rust/darth-rust/tree/master/tests

use darth_rust::DarthRust;
use serde::{Deserialize, Serialize};

#[derive(DarthRust, Debug, Serialize, Deserialize)]
pub struct User {
    #[pattern(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$")]
    pub id: String,
    #[pattern(r"^[a-zA-Z]{3,20}\s[a-zA-Z]{3,20}$")]
    pub name: String,
    #[pattern(r"^[a-zA-Z]{6,20}")]
    pub password: String,
    #[pattern(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")]
    pub email: String,
    #[min(18)]
    #[max(30)]
    pub age: u8,
    pub friends: Vec<User>,
}

Contribution

...

License

MIT

Dependencies

~0.3–1.7MB
~35K SLoC