abi_stable/external_types/crossbeam_channel/
errors.rs

1use super::*;
2
3use crate::StableAbi;
4
5use std::{
6    error::Error as ErrorTrait,
7    fmt::{self, Debug, Display},
8};
9
10///////////////////////////////////////////////////////////////////////////////
11
12#[repr(transparent)]
13#[derive(PartialEq, Eq, Clone, Copy, StableAbi)]
14pub struct RSendError<T>(pub T);
15
16impl<T> RSendError<T> {
17    pub fn into_inner(self) -> T {
18        self.0
19    }
20}
21
22impl<T> Debug for RSendError<T> {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        f.pad("RSendError{..}")
25    }
26}
27
28impl<T> Display for RSendError<T> {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        f.pad("Attempting to send on a disconnected channel")
31    }
32}
33
34impl<T> ErrorTrait for RSendError<T> {}
35
36impl_from_rust_repr! {
37    impl[T] From<SendError<T>> for RSendError<T> {
38        fn(this){
39            RSendError(this.into_inner())
40        }
41    }
42}
43
44impl_into_rust_repr! {
45    impl[T] Into<SendError<T>> for RSendError<T> {
46        fn(this){
47            SendError(this.into_inner())
48        }
49    }
50}
51
52///////////////////////////////////////////////////////////////////////////////
53
54#[repr(C)]
55#[derive(PartialEq, Eq, Clone, Copy, StableAbi)]
56pub struct RRecvError;
57
58impl Debug for RRecvError {
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        f.pad("RRecvError{..}")
61    }
62}
63
64impl Display for RRecvError {
65    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66        f.pad("Attempting to recv on a disconnected channel")
67    }
68}
69
70impl ErrorTrait for RRecvError {}
71
72impl_from_rust_repr! {
73    impl From<RecvError> for RRecvError {
74        fn(_this){
75            RRecvError
76        }
77    }
78}
79
80impl_into_rust_repr! {
81    impl Into<RecvError> for RRecvError {
82        fn(_this){
83            RecvError
84        }
85    }
86}
87
88///////////////////////////////////////////////////////////////////////////////
89
90#[repr(u8)]
91#[derive(PartialEq, Eq, Clone, Copy, StableAbi)]
92pub enum RTrySendError<T> {
93    Full(T),
94    Disconnected(T),
95}
96
97impl<T> RTrySendError<T> {
98    pub fn into_inner(self) -> T {
99        match self {
100            RTrySendError::Full(v) => v,
101            RTrySendError::Disconnected(v) => v,
102        }
103    }
104    pub fn is_full(&self) -> bool {
105        matches!(self, RTrySendError::Full { .. })
106    }
107    pub fn is_disconnected(&self) -> bool {
108        matches!(self, RTrySendError::Disconnected { .. })
109    }
110}
111
112impl<T> Debug for RTrySendError<T> {
113    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114        let msg = match self {
115            RTrySendError::Full { .. } => "Full{..}",
116            RTrySendError::Disconnected { .. } => "Disconnected{..}",
117        };
118        f.pad(msg)
119    }
120}
121
122impl<T> Display for RTrySendError<T> {
123    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124        let msg = match self {
125            RTrySendError::Full { .. } => "Attempting to send on a full channel",
126            RTrySendError::Disconnected { .. } => "Attempting to send on a disconnected channel",
127        };
128        f.pad(msg)
129    }
130}
131
132impl<T> ErrorTrait for RTrySendError<T> {}
133
134impl_from_rust_repr! {
135    impl[T] From<TrySendError<T>> for RTrySendError<T> {
136        fn(this){
137            match this {
138                TrySendError::Full(v)=>
139                    RTrySendError::Full(v),
140                TrySendError::Disconnected(v)=>
141                    RTrySendError::Disconnected(v),
142            }
143        }
144    }
145}
146
147impl_into_rust_repr! {
148    impl[T] Into<TrySendError<T>> for RTrySendError<T> {
149        fn(this){
150            match this {
151                RTrySendError::Full(v)=>TrySendError::Full(v),
152                RTrySendError::Disconnected(v)=>TrySendError::Disconnected(v),
153            }
154        }
155    }
156}
157
158///////////////////////////////////////////////////////////////////////////////
159
160#[repr(u8)]
161#[derive(Debug, PartialEq, Eq, Clone, Copy, StableAbi)]
162pub enum RTryRecvError {
163    Empty,
164    Disconnected,
165}
166
167impl RTryRecvError {
168    pub fn is_empty(&self) -> bool {
169        *self == RTryRecvError::Empty
170    }
171
172    pub fn is_disconnected(&self) -> bool {
173        *self == RTryRecvError::Disconnected
174    }
175}
176
177impl Display for RTryRecvError {
178    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179        let msg = match self {
180            RTryRecvError::Empty { .. } => "Attempting to recv on an empty channel",
181            RTryRecvError::Disconnected { .. } => "Attempting to recv on a disconnected channel",
182        };
183        f.pad(msg)
184    }
185}
186
187impl ErrorTrait for RTryRecvError {}
188
189impl_from_rust_repr! {
190    impl From<TryRecvError> for RTryRecvError {
191        fn(this){
192            match this {
193                TryRecvError::Empty=>
194                    RTryRecvError::Empty,
195                TryRecvError::Disconnected=>
196                    RTryRecvError::Disconnected,
197            }
198        }
199    }
200}
201
202impl_into_rust_repr! {
203    impl Into<TryRecvError> for RTryRecvError {
204        fn(this){
205            match this {
206                RTryRecvError::Empty=>TryRecvError::Empty,
207                RTryRecvError::Disconnected=>TryRecvError::Disconnected,
208            }
209        }
210    }
211}
212
213///////////////////////////////////////////////////////////////////////////////
214
215#[repr(u8)]
216#[derive(PartialEq, Eq, Clone, Copy, StableAbi)]
217pub enum RSendTimeoutError<T> {
218    Timeout(T),
219    Disconnected(T),
220}
221
222impl<T> RSendTimeoutError<T> {
223    pub fn into_inner(self) -> T {
224        match self {
225            RSendTimeoutError::Timeout(v) => v,
226            RSendTimeoutError::Disconnected(v) => v,
227        }
228    }
229    pub fn is_timeout(&self) -> bool {
230        matches!(self, RSendTimeoutError::Timeout { .. })
231    }
232    pub fn is_disconnected(&self) -> bool {
233        matches!(self, RSendTimeoutError::Disconnected { .. })
234    }
235}
236
237impl<T> Debug for RSendTimeoutError<T> {
238    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
239        let msg = match self {
240            RSendTimeoutError::Timeout { .. } => "Timeout{..}",
241            RSendTimeoutError::Disconnected { .. } => "Disconnected{..}",
242        };
243        f.pad(msg)
244    }
245}
246
247impl<T> Display for RSendTimeoutError<T> {
248    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
249        let msg = match *self {
250            RSendTimeoutError::Timeout { .. } => "Timed out while attempting to send on a channel",
251            RSendTimeoutError::Disconnected { .. } => {
252                "Attempting to send on a disconnected channel"
253            }
254        };
255        f.pad(msg)
256    }
257}
258
259impl<T> ErrorTrait for RSendTimeoutError<T> {}
260
261impl_from_rust_repr! {
262    impl[T] From<SendTimeoutError<T>> for RSendTimeoutError<T> {
263        fn(this){
264            match this {
265                SendTimeoutError::Timeout(v)=>
266                    RSendTimeoutError::Timeout(v),
267                SendTimeoutError::Disconnected(v)=>
268                    RSendTimeoutError::Disconnected(v),
269            }
270        }
271    }
272}
273
274impl_into_rust_repr! {
275    impl[T] Into<SendTimeoutError<T>> for RSendTimeoutError<T> {
276        fn(this){
277            match this {
278                RSendTimeoutError::Timeout(v)=>
279                    SendTimeoutError::Timeout(v),
280                RSendTimeoutError::Disconnected(v)=>
281                    SendTimeoutError::Disconnected(v),
282            }
283        }
284    }
285}
286
287///////////////////////////////////////////////////////////////////////////////
288
289#[repr(u8)]
290#[derive(Debug, PartialEq, Eq, Clone, Copy, StableAbi)]
291pub enum RRecvTimeoutError {
292    Timeout,
293    Disconnected,
294}
295
296impl RRecvTimeoutError {
297    pub fn is_timeout(&self) -> bool {
298        matches!(self, RRecvTimeoutError::Timeout { .. })
299    }
300    pub fn is_disconnected(&self) -> bool {
301        matches!(self, RRecvTimeoutError::Disconnected { .. })
302    }
303}
304
305impl Display for RRecvTimeoutError {
306    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
307        let msg = match self {
308            RRecvTimeoutError::Timeout { .. } => "Timed out while attempting to recv on a channel",
309            RRecvTimeoutError::Disconnected { .. } => {
310                "Attempting to recv on a disconnected channel"
311            }
312        };
313        f.pad(msg)
314    }
315}
316
317impl ErrorTrait for RRecvTimeoutError {}
318
319impl_from_rust_repr! {
320    impl From<RecvTimeoutError> for RRecvTimeoutError {
321        fn(this){
322            match this {
323                RecvTimeoutError::Timeout=>
324                    RRecvTimeoutError::Timeout,
325                RecvTimeoutError::Disconnected=>
326                    RRecvTimeoutError::Disconnected,
327            }
328        }
329    }
330}
331
332impl_into_rust_repr! {
333    impl Into<RecvTimeoutError> for RRecvTimeoutError {
334        fn(this){
335            match this {
336                RRecvTimeoutError::Timeout=>
337                    RecvTimeoutError::Timeout,
338                RRecvTimeoutError::Disconnected=>
339                    RecvTimeoutError::Disconnected,
340            }
341        }
342    }
343}
344
345///////////////////////////////////////////////////////////////////////////////