Who Builds the Builder?
This is a short note on the builder pattern, or, rather, on the builder method pattern.
TL;DR: if you have
FooBuilder, consider adding a
builder method to
A more minimal solution is to rely just on
There are two problems with that:
First, it is hard to discover.
Nothing in the docs/signature of
FooBuilder, you need to look elsewhere to learn how to create a
I remember being puzzled at how to create a
GlobSet for exactly this reason.
In contrast, the
builder method is right there on
Foo, probably the first one.
Second, it is more annoying to use, as you need to import both
Foo::builder method often only one import suffices, as you don’t need to name the builder type.
Discussion on /r/rust.