Closed
Description
What it does
ToString shouldn’t be implemented directly: Display should be implemented instead
Currently there are no warnings to a direct ToString
impl.
Advantage
No response
Drawbacks
No response
Example
impl ToString for Point {
fn to_string(&self) -> String {
format!("({}, {})", self.x, self.y)
}
}
Could be written as:
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}