summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs7
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