Display
Explore how Rust’s Display trait enables formatted output for various types. Learn to apply trait bounds to functions for type compatibility with format macros, and understand the relationship between Display, ToString, and common string conversion methods.
We'll cover the following...
We'll cover the following...
Using the format macro, I can write a function that turns an i32 into a String:
But we’re all about type parameters these days. Can we generalize this to any type T?
Not like that apparently:
error[E0277]: `T` doesn't implement `std::fmt::Display`
--> src/main.rs:2:19
|
2 | format!("{}", x)
| ^ `T` cannot be formatted with the default formatter
...