5/5
# Hash map ## Example Execute the following command to run [`./solutions/examples/hash_map.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/hash_map/solutions/examples/hash_map.rs) ```shell cargo run --example hash_map ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/hash_map/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn init(address: String, amount: u32) -> HashMap<String, u32> { todo!(); } ``` Initialize a `HashMap`, insert the value `amount` at the key `address`. Return this hash map. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/hash_map.rs
Exercises are in ./exercises/src/lib.rs
Initialize a HashMap
, insert the value amount
at the key address
.
Return this hash map.
A hands-on guide to initializing Rust HashMaps - Discover how to create and populate a `HashMap`, a fundamental Rust collection for key-value storage. You'll practice by implementing a function to initialize a new `HashMap` and insert a specific address-amount pair.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025
Rust Developer
Rust Programming BasicsDuration: 6min
Duration: 18min
Duration: 47min
Duration: 15min
Duration: 19min
Duration: 8min
Duration: 12min
Duration: 46min
Duration: 14min
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025