Skip to content

Commit

Permalink
refactor: simplify lifetime annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
willothy committed Nov 2, 2024
1 parent 0dbc985 commit 6105353
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/mapref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, V> std::ops::Deref for MapRef<'_, '_, K, V>
impl<K, V> std::ops::Deref for MapRef<'_, K, V>
where
K: Eq + std::hash::Hash,
{
Expand All @@ -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 }
}
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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 }
}
Expand Down
4 changes: 2 additions & 2 deletions src/shard_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ where
}
}

pub async fn get<'a, 'b: 'a>(&'a self, key: &'b K) -> Option<MapRef<'a, 'b, K, V>> {
pub async fn get<'a>(&'a self, key: &'a K) -> Option<MapRef<'a, K, V>> {
let (shard, hash) = self.shard(key);

let reader = shard.read().await;
Expand All @@ -152,7 +152,7 @@ where
})
}

pub async fn get_mut<'a, 'b: 'a>(&'a self, key: &'b K) -> Option<MapRefMut<'a, 'b, K, V>> {
pub async fn get_mut<'a>(&'a self, key: &'a K) -> Option<MapRefMut<'a, K, V>> {
let (shard, hash) = self.shard(key);
let mut writer = shard.write().await;
writer
Expand Down

0 comments on commit 6105353

Please sign in to comment.