]> git.lizzy.rs Git - rust.git/commitdiff
add useless types to the styleguide
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 2 Feb 2021 12:41:57 +0000 (15:41 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 2 Feb 2021 12:41:57 +0000 (15:41 +0300)
docs/dev/style.md

index 0c5e2ad33cb0efb327ae8264cf70dce97e637dd3..e2f1b6996aff496c30e6149a645987563a7254bf 100644 (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.
 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
 
 Prefer `Default` to zero-argument `new` function