1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use concurrent_queue::PushError;
use std::any::Any;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
#[error("Process has been halted")]
pub struct HaltedError;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
pub enum RecvError {
#[error("Couldn't receive because the process has been halted")]
Halted,
#[error("Couldn't receive becuase the channel is closed and empty")]
ClosedAndEmpty,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
pub enum TryRecvError {
#[error("Couldn't receive because the process has been halted")]
Halted,
#[error("Couldn't receive because the channel is empty")]
Empty,
#[error("Couldn't receive becuase the channel is closed and empty")]
ClosedAndEmpty,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
pub enum TrySendError<M> {
#[error("Couldn't send message because Channel is closed")]
Closed(M),
#[error("Couldn't send message because Channel is full")]
Full(M),
}
impl<M> From<PushError<M>> for TrySendError<M> {
fn from(e: PushError<M>) -> Self {
match e {
PushError::Full(msg) => Self::Full(msg),
PushError::Closed(msg) => Self::Closed(msg),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
pub struct SendError<M>(pub M);
#[derive(Clone, PartialEq, Eq, Hash, Error)]
pub enum TrySpawnError<T> {
#[error("Couldn't spawn process because the actor has exited")]
Exited(T),
#[error("Couldn't spawn process because the given inbox-type is incorrect")]
IncorrectType(T),
}
impl<T> std::fmt::Debug for TrySpawnError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Exited(_) => f.debug_tuple("Exited").finish(),
Self::IncorrectType(_) => f.debug_tuple("IncorrectType").finish(),
}
}
}
#[derive(Clone, PartialEq, Eq, Hash, Error)]
#[error("Couldn't spawn process because the channel has exited")]
pub struct SpawnError<T>(pub T);
impl<T> std::fmt::Debug for SpawnError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("SpawnError").finish()
}
}
#[derive(Debug, Error)]
pub enum ExitError {
#[error("Process has exited because of a panic")]
Panic(Box<dyn Any + Send>),
#[error("Process has exited because it was aborted")]
Abort,
}
impl ExitError {
pub fn is_panic(&self) -> bool {
match self {
ExitError::Panic(_) => true,
ExitError::Abort => false,
}
}
pub fn is_abort(&self) -> bool {
match self {
ExitError::Panic(_) => false,
ExitError::Abort => true,
}
}
}
impl From<tokio::task::JoinError> for ExitError {
fn from(e: tokio::task::JoinError) -> Self {
match e.try_into_panic() {
Ok(panic) => ExitError::Panic(panic),
Err(_) => ExitError::Abort,
}
}
}