January 2018
Beginner to intermediate
454 pages
10h 8m
English
A builder pattern is meant to be able to build a final object through multiple calls that can be chained. An excellent example is the OpenOptions type in the Rust standard library.
use std::fs::OpenOptions;
let file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open("foo.txt");
To make such APIs, you have two ways:
Let's start with the mutable borrows!