screeps/enums/action_error_codes/
constructionsite_error_codes.rs1use std::{error::Error, fmt};
2
3use num_derive::FromPrimitive;
4use serde_repr::{Deserialize_repr, Serialize_repr};
5
6use crate::{constants::ErrorCode, FromReturnCode};
7
8#[derive(
15 Debug, PartialEq, Eq, Clone, Copy, Hash, FromPrimitive, Deserialize_repr, Serialize_repr,
16)]
17#[repr(i8)]
18pub enum ConstructionSiteRemoveErrorCode {
19 NotOwner = -1,
20}
21
22impl FromReturnCode for ConstructionSiteRemoveErrorCode {
23 type Error = Self;
24
25 fn result_from_i8(val: i8) -> Result<(), Self::Error> {
26 let maybe_result = Self::try_result_from_i8(val);
27 #[cfg(feature = "unsafe-return-conversion")]
28 unsafe {
29 maybe_result.unwrap_unchecked()
30 }
31 #[cfg(not(feature = "unsafe-return-conversion"))]
32 maybe_result.unwrap()
33 }
34
35 fn try_result_from_i8(val: i8) -> Option<Result<(), Self::Error>> {
36 match val {
37 0 => Some(Ok(())),
38 -1 => Some(Err(ConstructionSiteRemoveErrorCode::NotOwner)),
39 _ => None,
40 }
41 }
42}
43
44impl fmt::Display for ConstructionSiteRemoveErrorCode {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 let msg: &'static str = match self {
47 ConstructionSiteRemoveErrorCode::NotOwner => {
48 "you are not the owner of this construction site, and it's not in your room"
49 }
50 };
51
52 write!(f, "{}", msg)
53 }
54}
55
56impl Error for ConstructionSiteRemoveErrorCode {}
57
58impl From<ConstructionSiteRemoveErrorCode> for ErrorCode {
59 fn from(value: ConstructionSiteRemoveErrorCode) -> Self {
60 Self::result_from_i8(value as i8).unwrap_err()
67 }
68}