Crate assemblist

Source
Expand description

A macro to easily create immutable builders.

The builder pattern is encouraged in the Rust language, in particular as a strategy to emulate named and optional arguments, which are intentionally not supported by Rust. However creating all the builder machinery can lead to boilerplate code, in particular when the generated data is complex and multi-layered. The usual builder pattern is based on mutation and generally turns compile-time checks that the final object is complete to a runtime verification. Assemblist allows you to create fluent immutable builders structured as method chains like in:

fn define_movie<'a>(name: &'a str)
    .released_in(release_year: usize)
    .directed_by(director_name: &'a str) -> Movie
{
   Movie {
       name: name.to_string(),
       release_year,
       director_name: director_name.to_string(),
   }
}

You can then just call it as it was declared:

let movie = define_movie("The Lobster")
    .released_in(2015)
    .directed_by("Yorgos Lanthimos");

Macrosยง

assemblist
The point of this crate. Allows to generate fluent immutable builders based on method chains.