]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/inherent_to_string.txt
Rollup merge of #100291 - WaffleLapkin:cstr_const_methods, r=oli-obk
[rust.git] / src / tools / clippy / src / docs / inherent_to_string.txt
1 ### What it does
2 Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`.
3
4 ### Why is this bad?
5 This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred.
6
7 ### Example
8 ```
9 pub struct A;
10
11 impl A {
12     pub fn to_string(&self) -> String {
13         "I am A".to_string()
14     }
15 }
16 ```
17
18 Use instead:
19 ```
20 use std::fmt;
21
22 pub struct A;
23
24 impl fmt::Display for A {
25     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26         write!(f, "I am A")
27     }
28 }
29 ```