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
|
struct Container<K: Eq, V> {
values: Vec<(K, V)>,
}
impl<K: Eq, V> Container<K, V> {
fn new() -> Self {
Self { values: vec![] }
}
fn insert(&mut self, k: K, v: V) { /* FIXME */
}
fn get(&self, k: &K) -> Option<&V> {
None
}
}
fn main() {
let alice = "alice".to_string();
let bob = "bob".to_string();
let robert = "Robert".to_string();
let mut cont = Container::new();
cont.insert(bob.clone(), bob.clone());
cont.insert(bob.clone(), robert);
println!("{} -> {:?}", &alice, cont.get(&alice));
println!("{} -> {:?}", &bob, cont.get(&bob));
// Output should be Robert
}
|