Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple bound locations lint #59

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,20 @@ impl<K: Clone + Eq + Hash, V, S: BuildHasher, W: WeightScale<K, V>> CLruCache<K,

/// Returns a reference to the value of the key in the cache or `None` if it is not present in the cache.
/// Moves the key to the head of the LRU list if it exists.
pub fn get<Q: ?Sized>(&mut self, key: &Q) -> Option<&V>
pub fn get<Q>(&mut self, key: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
let idx = *self.lookup.get(key)?;
self.storage.move_front(idx).map(|node| &node.value)
}

/// Removes and returns the value corresponding to the key from the cache or `None` if it does not exist.
pub fn pop<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
pub fn pop<Q>(&mut self, key: &Q) -> Option<V>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
let idx = self.lookup.remove(key)?;
self.storage.remove(idx).map(|CLruNode { key, value, .. }| {
Expand Down Expand Up @@ -397,21 +397,21 @@ impl<K: Clone + Eq + Hash, V, S: BuildHasher, W: WeightScale<K, V>> CLruCache<K,

/// Returns a reference to the value corresponding to the key in the cache or `None` if it is not present in the cache.
/// Unlike `get`, `peek` does not update the LRU list so the key's position will be unchanged.
pub fn peek<Q: ?Sized>(&self, key: &Q) -> Option<&V>
pub fn peek<Q>(&self, key: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
let idx = *self.lookup.get(key)?;
self.storage.get(idx).map(|node| &node.value)
}

/// Returns a bool indicating whether the given key is in the cache.
/// Does not update the LRU list.
pub fn contains<Q: ?Sized>(&mut self, key: &Q) -> bool
pub fn contains<Q>(&mut self, key: &Q) -> bool
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
self.peek(key).is_some()
}
Expand Down Expand Up @@ -631,21 +631,21 @@ impl<K: Clone + Eq + Hash, V, S: BuildHasher> CLruCache<K, V, S> {

/// Returns a mutable reference to the value of the key in the cache or `None` if it is not present in the cache.
/// Moves the key to the head of the LRU list if it exists.
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
let idx = *self.lookup.get(key)?;
self.storage.move_front(idx).map(|node| &mut node.value)
}

/// Returns a mutable reference to the value corresponding to the key in the cache or `None` if it is not present in the cache.
/// Unlike `get_mut`, `peek_mut` does not update the LRU list so the key's position will be unchanged.
pub fn peek_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V>
pub fn peek_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
let idx = *self.lookup.get(key)?;
self.storage.get_mut(idx).map(|node| &mut node.value)
Expand Down
Loading