Crate secador

Crate secador 

Source
Expand description

A macro to reduce boilerplate code in Rust.

Sometimes you can’t DRY code with the type system alone. Different types may require code of the exact same form, but with different symbols. Generics can help, but not always.

This crate provides a way to substitute symbols into statements, arguments, fields, and even attributes. You can specify multiple sets of symbols to substitute, and the target code will be duplicated for each symbol.

§Example

secador::secador!(variable_iter, [some_method, another_method], {
    seca!(1);
    for x in some_container.__variable_iter().iter() {
        println!("{:?}", x);
    }
});

This expands to:

for x in some_container.some_method().iter() {
    println!("{:?}", x);
}
for x in some_container.another_method().iter() {
    println!("{:?}", x);
}

Macros§

secador
A macro to reduce boilerplate code in Rust. Takes a tuple of names, a list of substitution tuples, and a block of code. Each section marked with seca! in that block of code is duplicated for each substitution tuple, with each name (expressed as __name) replaced by the corresponding value in the tuple.
secador_multi
Like secador!, but allows multiple sets of names and substitution tuples. The substitution sets can lead to polynomial code expansion, so use with care.