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
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;
use super::super::errors::SystemError;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SystemResult<S> {
Ok(S),
#[serde(rename = "error")]
Err(SystemError),
}
impl<S> SystemResult<S> {
pub fn into_result(self) -> Result<S, SystemError> {
Result::<S, SystemError>::from(self)
}
pub fn unwrap(self) -> S {
self.into_result().unwrap()
}
}
impl<S: fmt::Debug> SystemResult<S> {
pub fn unwrap_err(self) -> SystemError {
self.into_result().unwrap_err()
}
}
impl<S> From<Result<S, SystemError>> for SystemResult<S> {
fn from(original: Result<S, SystemError>) -> SystemResult<S> {
match original {
Ok(value) => SystemResult::Ok(value),
Err(err) => SystemResult::Err(err),
}
}
}
impl<S> From<SystemResult<S>> for Result<S, SystemError> {
fn from(original: SystemResult<S>) -> Result<S, SystemError> {
match original {
SystemResult::Ok(value) => Ok(value),
SystemResult::Err(err) => Err(err),
}
}
}