From: Aleksey Kladov Date: Thu, 7 Jan 2021 16:27:47 +0000 (+0300) Subject: Document `std::ops` style X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=eb710a63ca94409dd410ebde57923bcaf48f2975;p=rust.git Document `std::ops` style --- diff --git a/docs/dev/style.md b/docs/dev/style.md index d91a9108e1a..be2c7784730 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md @@ -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