Learning the language it's been surprising to me I cannot print an instance of Vec
:
fn main() {
let v1 = vec![1, 2, 3];
println!("{}", v1);
}
error[E0277]: `std::vec::Vec<{integer}>` doesn't implement `std::fmt::Display`
--> src/main.rs:3:20
|
3 | println!("{}", v1);
| ^^ `std::vec::Vec<{integer}>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `std::vec::Vec<{integer}>`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required by `std::fmt::Display::fmt`
I can understand that and I'm aware of using {:?}
debug placeholder as described here. Unfortunately, I don't yet understand the answer that tells why I cannot do that. It would be pretty trivial task for either C# or Haskell, wouldn't it? I'd implement the Display
trait for Vec<T>
for any T
that is serializable (or convertible to String
). Can I have a different explanation on why I can't do that? Is it a limitation of the type system?