diff --git a/src/lib.rs b/src/lib.rs index 2c49e24..3cf88be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -482,9 +482,9 @@ impl LruCache { /// assert_eq!(cache.get_key_value("3"), Some((&String::from("3"), &"d"))); /// ``` pub fn get_key_value<'a, Q>(&'a mut self, k: &Q) -> Option<(&'a K, &'a V)> - where - K: Borrow, - Q: Hash + Eq + ?Sized, + where + K: Borrow, + Q: Hash + Eq + ?Sized, { if let Some(node) = self.map.get_mut(KeyWrapper::from_ref(k)) { let node_ptr: *mut LruEntry = node.as_ptr(); @@ -2243,6 +2243,22 @@ mod tests { assert_eq!(cache.pop_lru(), Some((0, 0))); assert_eq!(cache.pop_lru(), None); } + + #[test] + fn test_get_key_value() { + use alloc::string::String; + + let mut cache = LruCache::new(NonZeroUsize::new(2).unwrap()); + + let key = String::from("apple"); + cache.put(key, "red"); + + assert_eq!( + cache.get_key_value("apple"), + Some((&String::from("apple"), &"red")) + ); + assert_eq!(cache.get_key_value("banana"), None); + } } /// Doctests for what should *not* compile