using
The using
macro allows simplified implementation and usage of the builder pattern
without having to return &mut Self
or Self
from the builder methods:
let vec3 = using!;
The using
macro allows calling multiple methods on the same object,
which is also known as method cascading.
In the example above, the following code is generated:
let vec3 = ;
This allows more flexibility for implementing and using builders and also makes more complicated use-cases more ergonomic:
// "Conventional" builder with method chaining:
let mut builder = new
.x
.y;
if some_condition
if some_other_condition
let thing = builder.build;
// Using Builder with `using`:
let thing = using!;
Although using
was primarily designed for the builder pattern,
it is not limited to that as it can be used on basically every type:
let hello_world = using!;
assert_eq!;