Coggle requires JavaScript to display documents.
HashMap
use std::collections::HashMap; let scores = HashMap::new(); scores.insert(String::from("blue"), 10); scores.insert(String::from("yellow"), 25);
use std::collections::HaspMap; let scores = HashMap::new(); scores.insert(String::from("blue"), 10); scores.entry(String::from("yellow")).or_insert(50); scores.entry(String::from("blue")).or_insert(50);
use std::collections::HashMap; let text = "hello world wonderful world"; let map = HashMap::new(); for word in text.split_whitespace() { let count = map.entry(word).or_insert(0); *count += 1; }
use std::collections::HashMap; let mut s = HashMap::new(); s.insert(String::from("blue"), 10); s.insert(String::from("blue"), 25);
use std::collections::HashMap; let teams = vec![String::from("blue"), String::from("yellow")]; let initial_scores = vec![10, 50]; let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect();
String
get()
use std::collections::HashMap; let scores = HaspMap::new(); scores.insert(String::from("yellow"), 10); scores.insert(String::from("blue"), 50); let team_name = String::from("blue"); let score = scores.get(&team_name);
Option<&V>
for
use std::collections::HashMap; let scores = HaspMap::new(); scores.insert(String::from("blue"), 10); scores.insert(String::from("yellow"), 50); for (key, value) in &scores { println!("{}: {}", key, value); }
HashMap<K, V>