From eb710a63ca94409dd410ebde57923bcaf48f2975 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 Jan 2021 19:27:47 +0300 Subject: Document `std::ops` style --- docs/dev/style.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'docs/dev') diff --git a/docs/dev/style.md b/docs/dev/style.md index d91a9108e..be2c77847 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 -- cgit v1.2.3