MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / basic

Function basic

publication/code/chapter06/hashmap.rs:221–240  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

219 iter();
220
221 fn basic() {
222 let mut hmap = HashMap::new(11);
223 hmap.insert(2,"dog");
224 hmap.insert(3,"tiger");
225 hmap.insert(10,"cat");
226
227 println!("empty: {}, size: {:?}", hmap.is_empty(), hmap.len());
228 println!("contains key 2: {}", hmap.contains(2));
229
230 println!("key 3: {:?}", hmap.get(3));
231 let val_ptr = hmap.get_mut(3).unwrap();
232 *val_ptr = "fish";
233 println!("key 3: {:?}", hmap.get(3));
234
235 println!("remove key 3: {:?}", hmap.remove(3));
236 println!("remove key 3: {:?}", hmap.remove(3));
237
238 hmap.clear();
239 println!("empty: {}, size: {:?}", hmap.is_empty(), hmap.len());
240 }
241
242 fn iter() {
243 let mut hmap = HashMap::new(11);

Callers 1

mainFunction · 0.70

Calls 3

insertMethod · 0.45
get_mutMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected