1use std::{marker::PhantomData, ops::Deref};
2
3use smithay_client_toolkit::reexports::client::{Dispatch, Proxy};
4
5#[derive(Debug)]
6pub struct WlTyped<I, DATA>(I, PhantomData<DATA>);
7
8impl<I, DATA> WlTyped<I, DATA>
9where
10 I: Proxy,
11 DATA: Send + Sync + 'static,
12{
13 #[allow(clippy::extra_unused_type_parameters)]
14 pub fn wrap<STATE>(i: I) -> Self
15 where
16 STATE: Dispatch<I, DATA>,
17 {
18 Self(i, PhantomData)
19 }
20
21 pub fn inner(&self) -> &I {
22 &self.0
23 }
24
25 #[allow(dead_code)]
26 pub fn data(&self) -> &DATA {
27 // Generic on Self::wrap makes sure that this will never panic
28 #[allow(clippy::unwrap_used)]
29 self.0.data().unwrap()
30 }
31}
32
33impl<I: Clone, D> Clone for WlTyped<I, D> {
34 fn clone(&self) -> Self {
35 Self(self.0.clone(), PhantomData)
36 }
37}
38
39impl<I, D> Deref for WlTyped<I, D> {
40 type Target = I;
41
42 fn deref(&self) -> &Self::Target {
43 &self.0
44 }
45}
46
47impl<I: PartialEq, D> PartialEq for WlTyped<I, D> {
48 fn eq(&self, other: &Self) -> bool {
49 self.0 == other.0
50 }
51}
52impl<I: Eq, D> Eq for WlTyped<I, D> {}
53