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
use std::error::Error;
pub type HandlerError = Box<dyn Error + Send>;
#[derive(Debug)]
pub enum HandlerResult {
Continue,
Stop,
Error(HandlerError),
}
impl HandlerResult {
pub fn error<E>(err: E) -> Self
where
E: Error + Send + 'static,
{
HandlerResult::Error(Box::new(err))
}
}
impl From<()> for HandlerResult {
fn from(_: ()) -> Self {
HandlerResult::Continue
}
}
impl<T, E> From<Result<T, E>> for HandlerResult
where
T: Into<HandlerResult>,
E: Error + Send + Sync + 'static,
{
fn from(result: Result<T, E>) -> Self {
match result {
Ok(res) => res.into(),
Err(err) => HandlerResult::error(err),
}
}
}