]> git.lizzy.rs Git - rust.git/commitdiff
Document `std::ops` style
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 7 Jan 2021 16:27:47 +0000 (19:27 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 7 Jan 2021 16:27:47 +0000 (19:27 +0300)
docs/dev/style.md

index d91a9108e1acbbbb6a83087ad18d8f02979aa569..be2c778473029adcad1e24b8445bff152163993e 100644 (file)
@@ -435,7 +435,7 @@ Avoid local `use MyEnum::*` imports.
 
 Prefer `use crate::foo::bar` to `use super::bar`.
 
-When implementing `Debug` or `Display`, import `std::fmt`:
+When implementing traits from `std::fmt` or `std::ops`, import the module:
 
 ```rust
 // Good
@@ -449,6 +449,14 @@ impl fmt::Display for RenameError {
 impl std::fmt::Display for RenameError {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { .. }
 }
+
+// Not as good
+use std::ops::Deref;
+
+impl Deref for Widget {
+    type Target = str;
+    fn deref(&self) -> &str { .. }
+}
 ```
 
 ## Order of Items