1#[cfg(feature = "serde")]
4#[macro_use]
5extern crate serde;
6
7mod enums;
8pub use enums::*;
9
10pub mod canifier;
11pub mod logger;
12pub mod mot;
13pub mod pigeon;
14
15use std::fmt;
16
17impl ErrorCode {
18 #[inline]
20 pub fn is_ok(self) -> bool {
21 self == ErrorCode::OK
22 }
23
24 #[inline]
26 pub fn is_err(self) -> bool {
27 self != ErrorCode::OK
28 }
29
30 pub fn or(self, err: Self) -> Self {
33 match self {
34 ErrorCode::OK => err,
35 _ => self,
36 }
37 }
38
39 pub fn into_res(self) -> Result<(), Self> {
41 match self {
42 ErrorCode::OK => Ok(()),
43 _ => Err(self),
44 }
45 }
46}
47
48impl std::error::Error for ErrorCode {
49 fn description(&self) -> &str {
50 "Error in CTRE Phoenix"
51 }
52}
53
54impl fmt::Display for ErrorCode {
55 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56 write!(f, "{:?}", self)
58 }
59}
60
61#[cfg(feature = "try_trait")]
62impl std::ops::Try for ErrorCode {
63 type Ok = ();
64 type Error = Self;
65
66 fn into_result(self) -> Result<(), Self> {
67 match self {
68 ErrorCode::OK => Ok(()),
69 _ => Err(self),
70 }
71 }
72
73 fn from_error(v: Self) -> Self {
74 v
75 }
76 fn from_ok(v: ()) -> Self {
77 ErrorCode::OK
78 }
79}