From 283c3b0133ec4d3217a29547a45092d6e64e4935 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Feb 2021 15:41:57 +0300 Subject: add useless types to the styleguide --- docs/dev/style.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'docs') 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. Borrowed own data discloses irrelevant details about origin of data. Irrelevant (neither right nor wrong) things obscure correctness. +## Useless Types + +More generally, always prefer types on the left + +```rust +// GOOD BAD +&[T] &Vec +&str &String +Option<&T> &Option +``` + +**Rationale:** types on the left are strictly more general. +Even when generality is not required, consistency is important. + ## Constructors Prefer `Default` to zero-argument `new` function -- cgit v1.2.3