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