0

Rust – Display Contents of Array, Tuple, HashMap and Vector

This post is about displaying the contents of Arrays , Tuples , HashMaps  and Vectors  in Rust.

Debug Trait

These three compound types, by default, implement the Debug trait. We use the following display formatters with println!  or print! functions to display their contents.

  • {:?}
    • single-line display
  • {:#?}
    • pretty-print alternative

For struct instances, please check out How to Display the Contents of Struct

Examples

Arrays

Output

Tuples

Output

HashMaps

Output

Vectors

Output

Complete Codes

These codes are a bit different as we pass our Vec  and HashMap  instances into my_tuple.

Output

Test with Rust 1.37.0.

Karl San Gabriel

Karl San Gabriel

Professional Software Developer