# Print a Vec in Rust

> Print a Rust Vec with {:?} or {:#?}, understand why {} fails, and format vector elements yourself when you need user-facing output.

HTML: https://rustprint.com/debug/print-vec/

Use `{:?}` to print a `Vec` for debugging. With captured identifiers, the compact form is `println!("{values:?}")`. Use `{:#?}` when a multi-line pretty Debug representation is easier to read.

**Print a Vec with compact and pretty Debug**

```rust
let values = vec![1, 2, 3];
println!("{values:?}");
println!("{values:#?}");
```

The example is executed by RustPrint's Rust test suite. The test checks the Debug representation for the values without treating the exact Debug text as a stable serialization format.

## Why the default Display formatter fails

A `Vec` supports `Debug` when its elements support `Debug`, but it does not provide the general-purpose `Display` representation required by `{}`.

**A Vec cannot use the default {} formatter**

```rust
fn main() {
    let values = vec![1, 2, 3];
    println!("{values}");
}
```

That failure is compiled intentionally in CI and must continue to produce the expected stable-Rust diagnostic.

If you hit E0277 from `{}`, see [type doesn't implement Display](/errors/doesnt-implement-display/index.md) for the trait-level explanation.

## Compact vs pretty output

`{:?}` is convenient for a short vector. `{:#?}` asks the `Debug` implementation for its pretty representation and is usually easier to scan when the vector is long or contains nested values.

Debug output is for inspection. Rust does not promise a stable textual Debug representation, so do not parse it, persist it as a file format, or depend on its exact punctuation.

## When you want user-facing output

If the vector represents text that users should read, choose the presentation yourself instead of exposing Debug output. For a list of strings, joining the elements is one simple option:

**Join string elements for deliberate user-facing output**

```rust
let names = vec!["Ada", "Linus", "Grace"];
println!("{}", names.join(", "));
```

For custom element types, implement or use their intended `Display` representation and decide how separators, brackets, labels, or localization should work at the collection level.

For the broader distinction, see [Debug vs Display](/debug/debug-vs-display/index.md).

## Sources

- [std::fmt::Debug](https://doc.rust-lang.org/std/fmt/trait.Debug.html)
- [std::vec::Vec](https://doc.rust-lang.org/std/vec/struct.Vec.html)

## Related RustPrint guides

- [Print a HashMap in Rust](/debug/print-hashmap/index.md): Print a Rust HashMap with {:?} or {:#?}, understand why entry order can change, and choose deterministic output when order matters.
- [Rust E0277: type doesn't implement Display](/errors/doesnt-implement-display/index.md): Fix Rust E0277 when a type cannot be formatted with {} because it does not implement std::fmt::Display.
- [Rust pretty print a struct with {:#?}](/debug/pretty-debug/index.md): Pretty print Rust structs, enums, maps, and nested values with {:#?}, derive Debug, and understand why Debug output is not a stable serialization format.
- [Debug vs Display in Rust](/debug/debug-vs-display/index.md): Choose between Rust Debug and Display based on programmer-facing inspection versus deliberate user-facing text.
