0

Rust – How to get Keys and Values from HashMap

In Rust, we can extract the keys and values from a HashMap using the iter()  and keys()  / get()  / unwrap()   functions.

Test Data

Using iter()

Note that iter()  return all key-value pairs in arbitrary order.

Output 1

Output 2

Using keys()

Note that keys()  also return keys in arbitrary order.

Output 1

Output 2

Karl San Gabriel

Karl San Gabriel

Professional Software Developer