1use crate::compat::*;
2
3use super::traits::*;
4
5#[derive(Clone, Debug)]
8pub struct ByPtr<K>(K);
9
10impl<K: WeakElement> WeakElement for ByPtr<K> {
11 type Strong = K::Strong;
12
13 fn new(view: &Self::Strong) -> Self {
14 ByPtr(K::new(view))
15 }
16
17 fn view(&self) -> Option<Self::Strong> {
18 self.0.view()
19 }
20}
21
22impl<K: WeakElement> WeakKey for ByPtr<K>
23 where K::Strong: Deref
24{
25 type Key = *const <K::Strong as Deref>::Target;
26
27 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