From 97440cfc6e5a19c12de492e33785c948c5318987 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 1 Apr 2025 11:43:04 +0200 Subject: [PATCH] chore: Implement `Lookup`/`HashEqLike` for `Arc` --- src/interned.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/interned.rs b/src/interned.rs index 01f39c9a7..1f1bd0dfe 100644 --- a/src/interned.rs +++ b/src/interned.rs @@ -6,6 +6,7 @@ use std::hash::{BuildHasher, Hash, Hasher}; use std::marker::PhantomData; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicU8, Ordering}; +use std::sync::Arc; use dashmap::SharedValue; @@ -542,6 +543,29 @@ where } } +impl<'a, T> HashEqLike<&'a T> for Arc +where + T: ?Sized + Hash + Eq, + Arc: From<&'a T>, +{ + fn hash(&self, h: &mut H) { + Hash::hash(self, &mut *h) + } + fn eq(&self, data: &&T) -> bool { + **self == **data + } +} + +impl<'a, T> Lookup> for &'a T +where + T: ?Sized + Hash + Eq, + Arc: From<&'a T>, +{ + fn into_owned(self) -> Arc { + Arc::from(self) + } +} + impl Lookup for &str { fn into_owned(self) -> String { self.to_owned()