Skip to content

Commit 9b51992

Browse files
authored
chore: Implement Lookup/HashEqLike for Arc (#784)
1 parent a89e3d2 commit 9b51992

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/interned.rs

+24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::hash::{BuildHasher, Hash, Hasher};
66
use std::marker::PhantomData;
77
use std::path::{Path, PathBuf};
88
use std::sync::atomic::{AtomicU8, Ordering};
9+
use std::sync::Arc;
910

1011
use dashmap::SharedValue;
1112

@@ -542,6 +543,29 @@ where
542543
}
543544
}
544545

546+
impl<'a, T> HashEqLike<&'a T> for Arc<T>
547+
where
548+
T: ?Sized + Hash + Eq,
549+
Arc<T>: From<&'a T>,
550+
{
551+
fn hash<H: Hasher>(&self, h: &mut H) {
552+
Hash::hash(self, &mut *h)
553+
}
554+
fn eq(&self, data: &&T) -> bool {
555+
**self == **data
556+
}
557+
}
558+
559+
impl<'a, T> Lookup<Arc<T>> for &'a T
560+
where
561+
T: ?Sized + Hash + Eq,
562+
Arc<T>: From<&'a T>,
563+
{
564+
fn into_owned(self) -> Arc<T> {
565+
Arc::from(self)
566+
}
567+
}
568+
545569
impl Lookup<String> for &str {
546570
fn into_owned(self) -> String {
547571
self.to_owned()

0 commit comments

Comments
 (0)