pflex_module_rs/
error_codes.rs1use crate::error_codes::ResponseCodes::{RobotPowerNotEnabled, Success, Warning};
5use std::fmt;
6
7pub type RobotError = String;
8pub type RobotOK = String;
9
10#[derive(Debug, PartialEq, Copy, Clone)]
12pub enum ResponseCodes {
13 Success = 0,
14 Warning = 1,
15 RobotPowerNotEnabled = -1046,
16}
17
18impl ResponseCodes {
19 pub fn check_code(code: String) -> Result<RobotOK, RobotError> {
20 match code.parse().unwrap() {
21 0 => Ok(Success.to_string()),
22 1 => Ok(Warning.to_string()),
23 -1046 => Err(RobotPowerNotEnabled.to_string()),
24 _ => Err(code),
25 }
26 }
27
28 pub fn value(&self) -> i32 {
30 *self as i32
31 }
32}
33
34impl fmt::Display for ResponseCodes {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 let code_description = match self {
37 Success => "Operation completed successfully without an error.",
38 Warning => "Operation completed with a warning.",
39 _ => "An error occurred during the operation.",
40 };
41 write!(f, "PFError {}: {}", self.value(), code_description)
42 }
43}