From 610535319fa11cbe02cd812b38de16fa9291b6f5 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Fri, 1 Nov 2024 20:29:22 -0700 Subject: [PATCH] refactor: simplify lifetime annotations --- src/mapref.rs | 30 +++++++++++++++--------------- src/shard_map.rs | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/mapref.rs b/src/mapref.rs index f4cf896..41934bd 100644 --- a/src/mapref.rs +++ b/src/mapref.rs @@ -26,14 +26,14 @@ use std::sync::{RwLockReadGuard, RwLockWriteGuard}; /// A reference to a key-value pair in a [`crate::ShardMap`]. Holds a shared (read-only) lock on the shard /// associated with the key. -pub struct MapRef<'a, 'b: 'a, K, V> { - key: &'b K, - value: &'b V, +pub struct MapRef<'a, K, V> { + key: &'a K, + value: &'a V, #[allow(unused)] reader: RwLockReadGuard<'a, HashTable<(K, V)>>, } -impl std::ops::Deref for MapRef<'_, '_, K, V> +impl std::ops::Deref for MapRef<'_, K, V> where K: Eq + std::hash::Hash, { @@ -44,14 +44,14 @@ where } } -impl<'a, 'b: 'a, K, V> MapRef<'a, 'b, K, V> +impl<'a, K, V> MapRef<'a, K, V> where K: Eq + std::hash::Hash, { pub(crate) fn new( reader: RwLockReadGuard<'a, HashTable<(K, V)>>, - key: &'b K, - value: &'b V, + key: &'a K, + value: &'a V, ) -> Self { Self { reader, key, value } } @@ -71,14 +71,14 @@ where /// A mutable reference to a key-value pair in a [`crate::ShardMap`]. Holds an exclusive lock on /// the shard associated with the key. -pub struct MapRefMut<'a, 'b: 'a, K, V> { - key: &'b K, - value: &'b mut V, +pub struct MapRefMut<'a, K, V> { + key: &'a K, + value: &'a mut V, #[allow(unused)] writer: RwLockWriteGuard<'a, HashTable<(K, V)>>, } -impl<'a, 'b: 'a, K, V> std::ops::Deref for MapRefMut<'a, 'b, K, V> +impl<'a, K, V> std::ops::Deref for MapRefMut<'a, K, V> where K: Eq + std::hash::Hash, { @@ -89,7 +89,7 @@ where } } -impl<'a, 'b, K, V> std::ops::DerefMut for MapRefMut<'a, 'b, K, V> +impl<'a, K, V> std::ops::DerefMut for MapRefMut<'a, K, V> where K: Eq + std::hash::Hash, { @@ -98,14 +98,14 @@ where } } -impl<'a, 'b: 'a, K, V> MapRefMut<'a, 'b, K, V> +impl<'a, K, V> MapRefMut<'a, K, V> where K: Eq + std::hash::Hash, { pub(crate) fn new( writer: RwLockWriteGuard<'a, HashTable<(K, V)>>, - key: &'b K, - value: &'b mut V, + key: &'a K, + value: &'a mut V, ) -> Self { Self { writer, key, value } } diff --git a/src/shard_map.rs b/src/shard_map.rs index 314958c..707fd7f 100644 --- a/src/shard_map.rs +++ b/src/shard_map.rs @@ -138,7 +138,7 @@ where } } - pub async fn get<'a, 'b: 'a>(&'a self, key: &'b K) -> Option> { + pub async fn get<'a>(&'a self, key: &'a K) -> Option> { let (shard, hash) = self.shard(key); let reader = shard.read().await; @@ -152,7 +152,7 @@ where }) } - pub async fn get_mut<'a, 'b: 'a>(&'a self, key: &'b K) -> Option> { + pub async fn get_mut<'a>(&'a self, key: &'a K) -> Option> { let (shard, hash) = self.shard(key); let mut writer = shard.write().await; writer