add useless types to the styleguide

This commit is contained in:
Aleksey Kladov 2021-02-02 15:41:57 +03:00
parent 8720f7f146
commit 283c3b0133

View File

@ -267,6 +267,20 @@ Non-local code properties degrade under change, privacy makes invariant local.
Borrowed own data discloses irrelevant details about origin of data. Borrowed own data discloses irrelevant details about origin of data.
Irrelevant (neither right nor wrong) things obscure correctness. Irrelevant (neither right nor wrong) things obscure correctness.
## Useless Types
More generally, always prefer types on the left
```rust
// GOOD BAD
&[T] &Vec<T>
&str &String
Option<&T> &Option<T>
```
**Rationale:** types on the left are strictly more general.
Even when generality is not required, consistency is important.
## Constructors ## Constructors
Prefer `Default` to zero-argument `new` function Prefer `Default` to zero-argument `new` function