1use core::fmt::Debug;
2
3pub trait ErrorType {
4 type Error: Debug;
5}
6
7impl<E> ErrorType for &E
8where
9 E: ErrorType,
10{
11 type Error = E::Error;
12}
13
14impl<E> ErrorType for &mut E
15where
16 E: ErrorType,
17{
18 type Error = E::Error;
19}
20
21pub trait Sender: ErrorType {
22 type Data<'a>;
23
24 fn send(&mut self, value: Self::Data<'_>) -> Result<(), Self::Error>;
25}
26
27impl<S> Sender for &mut S
28where
29 S: Sender,
30{
31 type Data<'a> = S::Data<'a>;
32
33 fn send(&mut self, value: Self::Data<'_>) -> Result<(), Self::Error> {
34 (**self).send(value)
35 }
36}
37
38pub trait Receiver: ErrorType {
39 type Data<'a>
40 where
41 Self: 'a;
42
43 fn recv(&mut self) -> Result<Self::Data<'_>, Self::Error>;
44}
45
46impl<R> Receiver for &mut R
47where
48 R: Receiver,
49{
50 type Data<'a>
51 = R::Data<'a>
52 where
53 Self: 'a;
54
55 fn recv(&mut self) -> Result<Self::Data<'_>, Self::Error> {
56 (**self).recv()
57 }
58}
59
60pub mod asynch {
61 pub use super::ErrorType;
62
63 pub trait Sender: ErrorType {
64 type Data<'a>: Send;
65
66 async fn send(&mut self, value: Self::Data<'_>) -> Result<(), Self::Error>;
67 }
68
69 impl<S> Sender for &mut S
70 where
71 S: Sender,
72 {
73 type Data<'a> = S::Data<'a>;
74
75 async fn send(&mut self, value: Self::Data<'_>) -> Result<(), Self::Error> {
76 (**self).send(value).await
77 }
78 }
79
80 pub trait Receiver: ErrorType {
81 type Data<'a>
82 where
83 Self: 'a;
84
85 async fn recv(&mut self) -> Result<Self::Data<'_>, Self::Error>;
86 }
87
88 impl<R> Receiver for &mut R
89 where
90 R: Receiver,
91 {
92 type Data<'a>
93 = R::Data<'a>
94 where
95 Self: 'a;
96
97 async fn recv(&mut self) -> Result<Self::Data<'_>, Self::Error> {
98 (**self).recv().await
99 }
100 }
101}