diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-03-22 20:19:16 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-03-22 20:19:16 +0200 |
commit | e0f9f6be4276d926aa9cef76f2dc407063a4f435 (patch) | |
tree | dc1375d83b24af9e0772424d48ed65a0b8521aea | |
parent | 67b7517232eaaea284f9ff85cc64ac7049070a81 (diff) | |
download | keyvalue-e0f9f6be4276d926aa9cef76f2dc407063a4f435.tar.gz |
we have a Robert!
Sponsored-by: author
-rw-r--r-- | src/main.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 0bf2c9f..c229269 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#[derive(Debug)] struct Container<K: Eq, V> { values: Vec<(K, V)>, } @@ -12,12 +13,13 @@ impl<K: Eq, V> Container<K, V> { } fn get(&self, k: &K) -> Option<&V> { + let mut value = None; for (actual_k, v) in self.values.iter() { if actual_k == k { - return Some(&v); + value = Some(v); } } - None + value } } @@ -28,6 +30,7 @@ fn main() { let mut cont = Container::new(); cont.insert(bob.clone(), bob.clone()); cont.insert(bob.clone(), robert); + println!("values: {:?}", cont); println!("{} -> {:?}", &alice, cont.get(&alice)); println!("{} -> {:?}", &bob, cont.get(&bob)); // Output should be Robert |