#![allow(dead_code)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] use std::collections::HashMap; fn main() { let mut dictionary:HashMap = HashMap::new(); println!("dictionary size: {}", dictionary.len()); println!("dictionary is {}", (if dictionary.is_empty() { "empty" } else { "not empty" })); dictionary.insert("apple", "red"); dictionary.insert("banana", "yellow"); dictionary.insert("cantaloupe", "orange"); dictionary.insert("dragonfruit", "red"); dictionary.insert("elderberry", "purple"); println!("dictionary size: {}", dictionary.len()); println!("dictionary is {}", (if dictionary.is_empty() { "empty" } else { "not empty" })); println!("bananas are {}", dictionary.get("banana").unwrap()); let mut x:&'static str = "dragonfruit"; if dictionary.contains_key(x) { println!("{} are {}", x, dictionary.get(x).unwrap()); } else { println!("Can't find {}", x); } x = "fig"; if dictionary.contains_key(x) { println!("{} are {}", x, dictionary.get(x).unwrap()); } else { println!("Can't find {}", x); } x = "elderberry"; dictionary.remove(x); if dictionary.contains_key(x) { println!("{} are {}", x, dictionary.get(x).unwrap()); } else { println!("Can't find {}", x); } println!("{}", map_to_string!(dictionary)); }