How to print the contents of a vector (Vec) in Rust?
Hello! I just started learning Rust, and I have a problem with printing a vector. I'm writing a small program that collects numbers into a vector, and then I want to simply see what's inside. But when I try to use println! with the vector, the compiler complains.
Here's my code:
```rust
fn main() {
let numbers = vec![1, 2, 3, 4, 5];
println!("My vector: {}", numbers);
}
```
And I get this error:
```
error[E0277]: `Vec` doesn't implement `Display`
```
What does this mean? I thought I could just put a variable in curly braces, like in Python or JavaScript. Why doesn't Rust want to print the vector? How do I properly print its contents?
I need to see all the elements of the vector to debug my program. I tried writing `{:?}` instead of `{}`, but then it outputs
No answers yet.
Log in to leave an answer