-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashMap.rs
36 lines (30 loc) · 1.09 KB
/
HashMap.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::collections::HashMap;
fn call(number: &str) -> &str {
match number {
"798-1364"
=> "We're sorry, the call cannot be completed as dialed. Please hang up and try again.",
"645-7689"
=> "Hello, this is Mr. Awesome's Pizza. My name is Fred. What can I get for you today?",
_ => "Hi! Who is this again?"
}
}
fn main() {
let mut contacts = HashMap::new();
contacts.insert("Daniel", "798-1364");
contacts.insert("Ashley", "645-7689");
contacts.insert("Katie", "435-8291");
contacts.insert("Robert", "956-1745");
match contacts.get(&"Daniel") {
Some(&number) => println!("Calling Daniel: {}", call(number)),
_ => println!("Don't have Daniel's number."),
}
contacts.insert("Daniel", "164-6743");
match contacts.get(&"Ashley") {
Some(&number) => println!("Calling Ashley: {}", call(number)),
_ => println!("Don't have Ashley's number."),
}
contacts.remove(&("Ashley"));
for (contact, &number) in contacts.iter() {
println!("Calling {}: {}", contact, call(number));
}
}