Simplify MutexMap generic constraints.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
borrow::ToOwned,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
sync::{Arc, TryLockError::WouldBlock},
|
sync::{Arc, TryLockError::WouldBlock},
|
||||||
@@ -38,17 +39,15 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(self))]
|
#[tracing::instrument(level = "trace", skip(self))]
|
||||||
pub async fn lock<'a, K>(&'a self, k: &'a K) -> Guard<Key, Val>
|
pub async fn lock<K>(&self, k: &K) -> Guard<Key, Val>
|
||||||
where
|
where
|
||||||
K: Debug + Send + ?Sized + Sync,
|
K: Debug + Send + ?Sized + Sync + ToOwned<Owned = Key>,
|
||||||
Key: TryFrom<&'a K>,
|
|
||||||
<Key as TryFrom<&'a K>>::Error: Debug,
|
|
||||||
{
|
{
|
||||||
let val = self
|
let val = self
|
||||||
.map
|
.map
|
||||||
.lock()
|
.lock()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
.entry(k.try_into().expect("failed to construct key"))
|
.entry(k.to_owned())
|
||||||
.or_default()
|
.or_default()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
@@ -59,17 +58,15 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(self))]
|
#[tracing::instrument(level = "trace", skip(self))]
|
||||||
pub fn try_lock<'a, K>(&self, k: &'a K) -> Result<Guard<Key, Val>>
|
pub fn try_lock<K>(&self, k: &K) -> Result<Guard<Key, Val>>
|
||||||
where
|
where
|
||||||
K: Debug + Send + ?Sized + Sync,
|
K: Debug + Send + ?Sized + Sync + ToOwned<Owned = Key>,
|
||||||
Key: TryFrom<&'a K>,
|
|
||||||
<Key as TryFrom<&'a K>>::Error: Debug,
|
|
||||||
{
|
{
|
||||||
let val = self
|
let val = self
|
||||||
.map
|
.map
|
||||||
.lock()
|
.lock()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
.entry(k.try_into().expect("failed to construct key"))
|
.entry(k.to_owned())
|
||||||
.or_default()
|
.or_default()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
@@ -82,11 +79,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(self))]
|
#[tracing::instrument(level = "trace", skip(self))]
|
||||||
pub fn try_try_lock<'a, K>(&self, k: &'a K) -> Result<Guard<Key, Val>>
|
pub fn try_try_lock<K>(&self, k: &K) -> Result<Guard<Key, Val>>
|
||||||
where
|
where
|
||||||
K: Debug + Send + ?Sized + Sync,
|
K: Debug + Send + ?Sized + Sync + ToOwned<Owned = Key>,
|
||||||
Key: TryFrom<&'a K>,
|
|
||||||
<Key as TryFrom<&'a K>>::Error: Debug,
|
|
||||||
{
|
{
|
||||||
let val = self
|
let val = self
|
||||||
.map
|
.map
|
||||||
@@ -95,7 +90,7 @@ where
|
|||||||
| WouldBlock => err!("would block"),
|
| WouldBlock => err!("would block"),
|
||||||
| _ => panic!("{e:?}"),
|
| _ => panic!("{e:?}"),
|
||||||
})?
|
})?
|
||||||
.entry(k.try_into().expect("failed to construct key"))
|
.entry(k.to_owned())
|
||||||
.or_default()
|
.or_default()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ impl super::Service {
|
|||||||
return Ok((result, true));
|
return Ok((result, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
let _dedup = self.resolving.lock(server_name.as_str());
|
let _dedup = self.resolving.lock(server_name);
|
||||||
if let Ok(result) = self.cache.get_destination(server_name).await {
|
if let Ok(result) = self.cache.get_destination(server_name).await {
|
||||||
return Ok((result, true));
|
return Ok((result, true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ mod well_known;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use tuwunel_core::{Result, arrayvec::ArrayString, smallstr::SmallString, utils::MutexMap};
|
use ruma::OwnedServerName;
|
||||||
|
use tuwunel_core::{Result, smallstr::SmallString, utils::MutexMap};
|
||||||
|
|
||||||
use self::{cache::Cache, dns::Resolver, fed::FedDest};
|
use self::{cache::Cache, dns::Resolver, fed::FedDest};
|
||||||
|
|
||||||
@@ -21,8 +22,7 @@ pub struct Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type DestString = SmallString<[u8; 40]>;
|
pub(crate) type DestString = SmallString<[u8; 40]>;
|
||||||
type Resolving = MutexMap<NameBuf, ()>;
|
type Resolving = MutexMap<OwnedServerName, ()>;
|
||||||
type NameBuf = ArrayString<256>;
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl crate::Service for Service {
|
impl crate::Service for Service {
|
||||||
|
|||||||
Reference in New Issue
Block a user