Skip to content

Commit 48fb831

Browse files
committed
Explain duplication of 'default' and 'new'. Fixes #38
1 parent ab788f7 commit 48fb831

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ The most important common traits to implement from `std` are:
536536
- [`Display`](https://doc.rust-lang.org/std/fmt/trait.Display.html)
537537
- [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)
538538

539+
Note that it is common and expected for types to implement both
540+
`Default` and an empty `new` constructor. `new` is the constructor
541+
convention in Rust, and users expect it to exist, so if it is
542+
reasonable for the basic constructor to take no arguments, then it
543+
should, even if it is functionally identical to `default`.
544+
539545
[C-CONV-TRAITS]: #c-conv-traits
540546
<a id="c-conv-traits"></a>
541547
### Conversions use the standard traits `From`, `AsRef`, `AsMut` (C-CONV-TRAITS)
@@ -1338,6 +1344,11 @@ let config = Config { color: Red, .. Config::new() };
13381344
[`std::io::Error::new`]: https://doc.rust-lang.org/std/io/struct.Error.html#method.new
13391345
[`std::io::Error::from_raw_os_error`]: https://doc.rust-lang.org/std/io/struct.Error.html#method.from_raw_os_error
13401346

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

13421353
<a id="flexibility"></a>
13431354
## Flexibility

0 commit comments

Comments
 (0)