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

To say that `new()` is not recommended when the type has a `Default` contradicts the official API guidelines #319

Closed jcornaz closed 2 years ago

jcornaz commented 2 years ago

Hi,

The unofficial patterns book says here:

Note: When implementing Default for a type, it is neither required nor recommended to also provide an associated function new without arguments.

Which contradicts the official API guidelines there:

Note that it is common and expected for types to implement both Default and an empty new constructor. new is the constructor convention in Rust, and users expect it to exist, so if it is reasonable for the basic constructor to take no arguments, then it should, even if it is functionally identical to default.

simonsan commented 2 years ago

Thanks for bringing that up, it's fixed now. 👍🏽