PAY ATTENTION! THE CRATE IS UNFINISHED!
Rust macro-library for Don't Repeating Yourself
DRYlib is a library that designed for reducing the amount of duplicate code.
Take a look at clones macros example from examples/clones.rs:
extern crate drylib;
use drylib::{clones, mutclones};
fn main() {
let digit = 2;
let vector = vec![1, 2, 3];
let string = "this is a string generated by the `clones`".to_owned();
clones!(digit, vector, string);
println!("cdigit: {cdigit}, cvector: {cvector:?}, cstring: {cstring}");
clones!(mut digit, vector, mut string);
cdigit = 4;
cstring = "this is a mutable cloned string generated by the `clones` macro".to_owned();
println!("cdigit: {cdigit}, cvector: {cvector:?}, cstring: {cstring}");
mutclones!(digit, vector, string);
cdigit = 4;
cvector = vec![4, 5, 6];
cstring = "this is a mutable cloned string generated by the `mutclones` macro".to_owned();
println!("cdigit: {cdigit}, cvector: {cvector:?}, cstring: {cstring}");
}
An then at the pubstruct macro example from examples/structs.rs:
extern crate drylib;
use drylib::*;
fn main() {
pubstruct!{
#[derive(Debug)]
Tuple(usize, i32, u32) };
let tuple = Tuple(0, 1, 2); println!("{tuple:?}");
pubstruct!{
#[derive(Debug)]
TupleT<T>(T, i32, u32)
};
let tuple_t = TupleT(0, 1, 2);
println!("{tuple_t:?}");
pubstruct!{
#[derive(Debug)]
StructureLT<'a> {
greet: &'a str,
digit: i32,
}
}
let structure_lt = StructureLT { greet: "hello again", digit: 1 };
println!("{structure_lt:?}");
pubstruct!{
#[derive(Debug)]
StructureLTTU<'a, 'b, T, U> {
greet: &'a T,
array: &'b Vec<U>,
}
}
let structure_lttu = StructureLTTU { greet: &"hello again", array: &vec![1, 2, 3] };
println!("{structure_lttu:?}"); }
In this library we have a lot of convenient little macros, That was just a small part of them.
I haven't created the examples for all of them but you can do a PR and help me with that.
There will be more and more macros in the future, the library is still far from its final version.