diff options
author | Aleksey Kladov <[email protected]> | 2021-02-02 12:41:57 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-02-02 12:41:57 +0000 |
commit | 283c3b0133ec4d3217a29547a45092d6e64e4935 (patch) | |
tree | 1c3f2e2cda9b579e70ee6b6c55a89b4428d0170b /docs | |
parent | 8720f7f14688257d320de44e1354c62fce1a6bcf (diff) |
add useless types to the styleguide
Diffstat (limited to 'docs')
-rw-r--r-- | docs/dev/style.md | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md index 0c5e2ad33..e2f1b6996 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md | |||
@@ -267,6 +267,20 @@ Non-local code properties degrade under change, privacy makes invariant local. | |||
267 | Borrowed own data discloses irrelevant details about origin of data. | 267 | Borrowed own data discloses irrelevant details about origin of data. |
268 | Irrelevant (neither right nor wrong) things obscure correctness. | 268 | Irrelevant (neither right nor wrong) things obscure correctness. |
269 | 269 | ||
270 | ## Useless Types | ||
271 | |||
272 | More generally, always prefer types on the left | ||
273 | |||
274 | ```rust | ||
275 | // GOOD BAD | ||
276 | &[T] &Vec<T> | ||
277 | &str &String | ||
278 | Option<&T> &Option<T> | ||
279 | ``` | ||
280 | |||
281 | **Rationale:** types on the left are strictly more general. | ||
282 | Even when generality is not required, consistency is important. | ||
283 | |||
270 | ## Constructors | 284 | ## Constructors |
271 | 285 | ||
272 | Prefer `Default` to zero-argument `new` function | 286 | Prefer `Default` to zero-argument `new` function |