1use thiserror::Error;
2
3use crate::RxError;
4
5#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Hash)]
8pub enum TrySendCheckedError<M> {
9 Full(M),
10 Closed(M),
11 NotAccepted(M),
12}
13
14#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Hash)]
17pub enum SendCheckedError<M> {
18 Closed(M),
19 NotAccepted(M),
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
24pub enum TrySendError<M> {
25 #[error("Couldn't send message because Channel is closed")]
27 Closed(M),
28 #[error("Couldn't send message because Channel is full")]
30 Full(M),
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
35pub struct SendError<M>(pub M);
36
37#[derive(Debug, thiserror::Error, Clone, Copy, PartialEq, Eq)]
41pub enum RequestError<M> {
42 NoReply,
43 Closed(M),
44}
45
46#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
50pub enum TryRequestError<M, E> {
51 NoReply(E),
52 Closed(M),
53 Full(M),
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
58pub enum RecvError {
59 #[error("Couldn't receive because the process has been halted")]
61 Halted,
62 #[error("Couldn't receive becuase the channel is closed and empty")]
65 ClosedAndEmpty,
66}
67
68#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
70pub enum TryRecvError {
71 #[error("Couldn't receive because the process has been halted")]
73 Halted,
74 #[error("Couldn't receive because the channel is empty")]
76 Empty,
77 #[error("Couldn't receive becuase the channel is closed and empty")]
80 ClosedAndEmpty,
81}
82
83#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
85#[error("Process has been halted")]
86pub struct Halted;
87
88impl<T> From<TrySendError<T>> for TrySendCheckedError<T> {
89 fn from(err: TrySendError<T>) -> Self {
90 match err {
91 TrySendError::Full(msg) => Self::Full(msg),
92 TrySendError::Closed(msg) => Self::Closed(msg),
93 }
94 }
95}
96
97impl<T> From<SendError<T>> for SendCheckedError<T> {
98 fn from(err: SendError<T>) -> Self {
99 Self::Closed(err.0)
100 }
101}
102
103impl<T> From<RxError> for RequestError<T> {
104 fn from(RxError: RxError) -> Self {
105 Self::NoReply
106 }
107}
108
109impl<T> From<SendError<T>> for RequestError<T> {
110 fn from(err: SendError<T>) -> Self {
111 Self::Closed(err.0)
112 }
113}