| Crates.io | with-macro |
| lib.rs | with-macro |
| version | 0.1.1 |
| created_at | 2019-01-24 00:04:19.061363+00 |
| updated_at | 2019-01-24 00:39:02.921532+00 |
| description | Syntactic sugar for calling methods |
| homepage | |
| repository | https://github.com/darkstalker/with-macro |
| max_upload_size | |
| id | 110316 |
| size | 7,584 |
with macroThis 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.
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]);