blob: b541f9e2f92f706759ad9cea16a5a1c9ca6ee8c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use std::ops::Deref;
use super::traits::*;
/// Wrapper struct for using pointer equality and hashes rather
/// than pointed-to value equality and hashes.
#[derive(Clone, Debug)]
pub struct ByPtr<K>(K);
impl<K: WeakElement> WeakElement for ByPtr<K> {
type Strong = K::Strong;
fn new(view: &Self::Strong) -> Self {
ByPtr(K::new(view))
}
fn view(&self) -> Option<Self::Strong> {
self.0.view()
}
}
impl<K: WeakElement> WeakKey for ByPtr<K>
where K::Strong: Deref
{
type Key = *const <K::Strong as Deref>::Target;
fn with_key<F, R>(view: &Self::Strong, f: F) -> R
where F: FnOnce(&Self::Key) -> R
{
f(&(view.deref() as *const _))
}
}
|