Merge pull request #594 from gvozdvmozgu/add-box-str-lookup
Some checks are pending
Book / Book (push) Waiting to run
Book / Deploy (push) Blocked by required conditions
Test / Test (false, beta) (push) Waiting to run
Test / Test (false, stable) (push) Waiting to run
Test / Test (true, nightly) (push) Waiting to run
Test / Miri (push) Waiting to run
Test / Benchmarks (push) Waiting to run

Add `Lookup<Box<T>>` for `&T`
This commit is contained in:
Micha Reiser 2024-10-15 09:08:29 +00:00 committed by GitHub
commit b14be5c039
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -360,6 +360,22 @@ where
} }
} }
impl<'a, T> Lookup<Box<T>> for &'a T
where
T: ?Sized + Hash + Eq,
Box<T>: From<&'a T>,
{
fn hash<H: Hasher>(&self, h: &mut H) {
Hash::hash(self, &mut *h)
}
fn eq(&self, data: &Box<T>) -> bool {
**self == **data
}
fn into_owned(self) -> Box<T> {
Box::from(self)
}
}
impl Lookup<String> for &str { impl Lookup<String> for &str {
fn hash<H: Hasher>(&self, h: &mut H) { fn hash<H: Hasher>(&self, h: &mut H) {
Hash::hash(self, &mut *h) Hash::hash(self, &mut *h)