drylib 0.1.23

Rust macro-library for Don't Repeating Yourself
Documentation
extern crate drylib;

use drylib::{clones, mutclones}; // Use the best library in the world

fn main() {
    // You can define variables that you want to clone:
    let digit = 2;
    let vector = vec![1, 2, 3];
    let string = "this is a string generated by the `clones`".to_owned();

    // And you can clone them with the `clones` macro:
    clones!(digit, vector, string); // Just type what variables you want to clone
    // The `clones` macro creates new variables using the following formula: 
    // format!({CLONES_PREFIX}{identifier(name) of the variable}).
    // By default CLONES_PREFIX is 'c', but you can specify it with following features:
    // [clones-prefix-c, clones-prefix-cl, and so on until clones-prefix-clone]
    // Select the one and prefixes will be appropriate.
    //
    // Therefore, the `clones` macro expands as follows:
    //
    // let cdigit = digit.clone();
    // let cvector = vector.clone();
    // let cstring = string.clone();

    // We can print them:
    println!("cdigit: {cdigit}, cvector: {cvector:?}, cstring: {cstring}");
    // This will print: cdigit: 2, cvector: [1, 2, 3], cstring: this is a string generated by the `clones`

    // By the way, you can use the `clones` macro specifying 
    // mutability of the variables that you want to clone as in here:
    clones!(mut digit, vector, mut string);
    // this one ^^^^^ and this one ^^^^^^ will be created as mutable variables, 
    // with the formula already described up above.
    //
    // This macro call expands as follows:
    //
    // let mut cdigit = digit.clone();
    // let cvector = vector.clone();
    // let mut cstring = string.clone();

    // The variables are mutable, so you can easily reassign them:
    cdigit = 4;
    cstring = "this is a mutable cloned string generated by the `clones` macro".to_owned();

    // And print:
    println!("cdigit: {cdigit}, cvector: {cvector:?}, cstring: {cstring}");
    // This will print: cdigit: 4, cvector: [1, 2, 3], cstring: this is a mutable cloned string generated by the `clones` macro

    // Here is another one, the `mutclones` macro, it does the same thing as the clones macro, 
    // but created variables are all mutable.
    mutclones!(digit, vector, string); // The `mutclones` macro expands in this code:
    //
    // let mut cdigit = digit.clone();
    // let mut cvector = vector.clone();
    // let mut cstring = string.clone();

    // The variables are mutable, therefore you can easily reassign them:
    cdigit = 4;
    cvector = vec![4, 5, 6];
    cstring = "this is a mutable cloned string generated by the `mutclones` macro".to_owned();

    // And print them:
    println!("cdigit: {cdigit}, cvector: {cvector:?}, cstring: {cstring}");
    // This will print: cdigit: 4, cvector: [4, 5, 6], cstring: this is a mutable cloned string generated by the `mutclones` macro
}