fish_lib/game/errors/
item_event.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum GameItemEventError {
5    #[error("Item with type_id '{type_id}' does not exist")]
6    InvalidItemType { type_id: i32 },
7    #[error("Item with type_id '{type_id}' is not a rod")]
8    NotARod { type_id: i32 },
9}
10
11impl GameItemEventError {
12    pub fn invalid_item_type(type_id: i32) -> Self {
13        Self::InvalidItemType { type_id }
14    }
15
16    pub fn not_a_rod(type_id: i32) -> Self {
17        Self::NotARod { type_id }
18    }
19
20    pub fn is_invalid_item_type(&self) -> bool {
21        matches!(self, Self::InvalidItemType { .. })
22    }
23
24    pub fn is_not_a_rod(&self) -> bool {
25        matches!(self, Self::NotARod { .. })
26    }
27
28    pub fn get_type_id(&self) -> Option<i32> {
29        match self {
30            Self::InvalidItemType { type_id } => Some(*type_id),
31            Self::NotARod { type_id } => Some(*type_id),
32            _ => None,
33        }
34    }
35}