1use std::fmt::{Display, Formatter};
2
3#[derive(Eq, PartialEq, Copy, Clone, Debug)]
5#[repr(i32)]
6pub enum Error {
7 Unknown = 1,
9
10 Success = 0,
12
13 InvalidValue = -30,
15
16 InvalidPlatform = -32,
18}
19
20impl Default for Error {
21 fn default() -> Self {
23 Error::Unknown
24 }
25}
26
27impl From<i32> for Error {
28 fn from(code: i32) -> Self {
29 match code {
30 0 => Error::Success,
31 -30 => Error::InvalidValue,
32 -32 => Error::InvalidPlatform,
33 _ => Error::Unknown,
34 }
35 }
36}
37
38impl Display for Error {
39 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40 match *self {
41 Error::Unknown => write!(f, "An unknown error occurred."),
42 Error::Success => write!(f, "The operation completed successfully."),
43 Error::InvalidValue => write!(f, "An invalid value was passed as parameter."),
44 Error::InvalidPlatform => write!(f, "An invalid platform ID was passed as parameter."),
45 }
46 }
47}
48
49pub type Result<T> = std::result::Result<T, Error>;
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn default_error_code() {
58 assert_eq!(Error::default(), Error::Unknown);
59 }
60}