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
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;
mod enums;
pub use enums::*;
pub mod canifier;
pub mod logger;
pub mod mot;
pub mod pigeon;
use std::fmt;
impl ErrorCode {
#[inline]
pub fn is_ok(self) -> bool {
self == ErrorCode::OK
}
#[inline]
pub fn is_err(self) -> bool {
self != ErrorCode::OK
}
pub fn or(self, err: Self) -> Self {
match self {
ErrorCode::OK => err,
_ => self,
}
}
pub fn into_res(self) -> Result<(), Self> {
match self {
ErrorCode::OK => Ok(()),
_ => Err(self),
}
}
}
impl std::error::Error for ErrorCode {
fn description(&self) -> &str {
"Error in CTRE Phoenix"
}
}
impl fmt::Display for ErrorCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
#[cfg(feature = "try_trait")]
impl std::ops::Try for ErrorCode {
type Ok = ();
type Error = Self;
fn into_result(self) -> Result<(), Self> {
match self {
ErrorCode::OK => Ok(()),
_ => Err(self),
}
}
fn from_error(v: Self) -> Self {
v
}
fn from_ok(v: ()) -> Self {
ErrorCode::OK
}
}