multicall 0.1.4

Macro to simplify multiple operations or calls on a single object
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 12.36 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 268.03 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TudbuT

Multicall

This library provides the multicall! macro, which allows you to apply multiple operations to one object without writing the name of the object again and again.

Syntax:

let mut test_variable = 1;
multicall! {
    expr:
    operation;
    set test_variable = operation;
    exec normal_operation(#);
    operation;
    ...
    {
        subexpr:
        operation;
        set test_variable += operation;
        exec normal_operation(#);
        operation;
        ...
    }; // this semicolon is mandatory.
}

Evaluates to:

let mut test_variable = 1;
{
    let __multicall_item__ = expr;
    __multicall_item__.operation;
    test_variable = __multicall_item__.operation;
    normal_operation(__multicall_item__);
    __multicall_item__.operation;
    ...
    {
        let __multicall_item__ = __multicall_item__.subexpr;
        __multicall_item__.operation;
        test_variable += __multicall_item__.operation;
        normal_operation(__multicall_item__);
        __multicall_item__.operation;
        ...
    };
}

Example:

use multicall::multicall;
use std::ops::AddAssign;
#[derive(Debug)]
struct Test { a: u32, b: i32 }

fn main() {
    let mut test = Test { a: 0, b: 0 };
    let b_plus_five;
    multicall! {
        &mut test:
        a = 5;
        b = 6;
        {
            b:
            add_assign(500);
        };
        {
            a:
            add_assign(58);
        };
        a.add_assign(100 - 58);
        set b_plus_five = b + 5;
        exec println!("{}, {}", #.a, #.b);
    }
    println!("{test:?}");
}

More in examples/.

Roadmap

  • Basic multicall syntax
  • set external variables
  • exec normal code
  • If statements
  • ... maybe more