]> git.lizzy.rs Git - rust.git/blob - src/docs/should_implement_trait.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / should_implement_trait.txt
1 ### What it does
2 Checks for methods that should live in a trait
3 implementation of a `std` trait (see [llogiq's blog
4 post](http://llogiq.github.io/2015/07/30/traits.html) for further
5 information) instead of an inherent implementation.
6
7 ### Why is this bad?
8 Implementing the traits improve ergonomics for users of
9 the code, often with very little cost. Also people seeing a `mul(...)`
10 method
11 may expect `*` to work equally, so you should have good reason to disappoint
12 them.
13
14 ### Example
15 ```
16 struct X;
17 impl X {
18     fn add(&self, other: &X) -> X {
19         // ..
20     }
21 }
22 ```