with-macro 0.1.1

Syntactic sugar for calling methods
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 7.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.07 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • wolfiestyle/with-macro
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wolfiestyle

The with macro

Build Status crates.io Documentation

This is a macro that takes an object and lets you call methods on that object without naming it. The first argument is an expression that will be assigned to a variable in let binding. To make that binding mutable, prepend mut to the expression. Calling a function that starts with a . will be converted into a method call using this variable.

The supported forms are:

  • .method(args..)
  • let pat = .method(args..);
  • var = .method(args..);

Anything else will be evaluated unmodified as an expression.

Usage

use with_macro::with;

let vec = with! {
    mut Vec::new() =>
        .push(1)
        .push(42)
        .push(-13)
        let l = .len();
        assert_eq!(l, 3);
};

assert_eq!(vec, [1, 42, -13]);