Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Call HashMap class in Rust standard library
- use std::collections::HashMap;
- fn main() {
- // Create an empty map
- let mut hash = HashMap::new(); // HashMap<&str, &str>
- // Insert (key, value) pairs into the map
- hash.insert("one", "eins");
- hash.insert("two", "zwei");
- hash.insert("three", "drei");
- // Get value by key
- assert_eq!(hash.get("one"), Some(&"eins"));
- // Get None when (key, value) doesn't exist
- assert_eq!(hash.get("four"), None);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement