![](/static/253f0d9b/assets/icons/icon-96x96.png)
![](https://lemmy.world/pictrs/image/d82718c7-5579-4676-8e2e-97b4188f10d3.png)
Didn’t want to install something to move stuff of my laptop yesterday. Took a USB which has both a boot partition and a data partition, which worked on my W10 computer and moved it to the W11 laptop and it wouldn’t recognize it…
Long story short, I had to manual set the partition id for the data part using diskpart for the data partition to be recognized. But that was a lot more effort than expected to move a few files over.
The difference is, with a build pattern you are sure someone set the required field.
For example, actix-web you create a HttpResponse, but you don’t actually have that stuct until you finish the object by setting the body() or by using finish() to have an empty body. Before that point you have a builder.
There is noting enforcing you to set the input_directory now, before trying to use it. Depending on what you need, that is no problem. Likewise, you default the max_depth to a value before a user sets one, also fine in itself. But if the expectation is that the user should always provide their own values, then a .configre(max_depth, path) would make sense to finish of the builder.
It might not matter much here, but if what you need to set was more expensive struts, then defaulting to something might not be a good idea. Or you don’t need to have Option<PathBuf> and check every time you use it, since you know a user provided it. But that is only if it is required.
Lastly, builder make a lot of sense when there is a lot to provide, which would make creating a strict in a single function/line very complicated.
Example in non-rust: https://stackoverflow.com/questions/328496/when-would-you-use-the-builder-pattern