screeps/local/object_id/
errors.rs

1use std::{error::Error, fmt, num::ParseIntError};
2
3#[derive(Debug, Clone)]
4pub enum RawObjectIdParseError {
5    Parse(ParseIntError),
6    LargeValue(u128),
7}
8
9impl fmt::Display for RawObjectIdParseError {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        match self {
12            RawObjectIdParseError::Parse(e) => {
13                write!(f, "error parsing object id hex digits: {e}")
14            }
15            RawObjectIdParseError::LargeValue(value) => write!(
16                f,
17                "string contained hex value too big be object id. \
18                 value {value} bigger than maximum for 24 digits"
19            ),
20        }
21    }
22}
23
24impl Error for RawObjectIdParseError {
25    fn cause(&self) -> Option<&dyn Error> {
26        match self {
27            RawObjectIdParseError::Parse(e) => Some(e),
28            RawObjectIdParseError::LargeValue(_) => None,
29        }
30    }
31}
32
33impl From<ParseIntError> for RawObjectIdParseError {
34    fn from(e: ParseIntError) -> Self {
35        RawObjectIdParseError::Parse(e)
36    }
37}
38
39impl RawObjectIdParseError {
40    pub(crate) const fn value_too_large(val: u128) -> Self {
41        RawObjectIdParseError::LargeValue(val)
42    }
43}