rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
8.02k stars 366 forks source link

Clarify naming convention of `build()` in section 3.2.1 #338

Open ElykDeer opened 1 year ago

ElykDeer commented 1 year ago

The current builder design pattern implies that the method the produces whatever is being built should be named build(), which seems to contradict the Rust API Guidelines on the same subject.

I think there should be some clarifying language around this: whether the method should always be named build(), or be adapted to fit the API.

wookietreiber commented 1 year ago

IMO recommending build() as a default is fine, if you can't think of any other name. I agree with you that clarification about this is good, e.g. a note that says something like that build() is used in the example, but if your API supports it to choose a better name, same as the API Guidelines say about the name of the builder type.