tf2_enum/
error.rs

1//! Provides error types.
2
3use crate::Spell;
4use std::fmt;
5
6pub use strum::ParseError;
7pub use num_enum::TryFromPrimitiveError;
8
9/// An error when attempting to convert a spell into a sub-set of spells (footprints or paint).
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub struct TryFromSpellError {
12    /// The defindex that was attempted to be converted.
13    pub defindex: u32,
14    /// The spell that was attempted to be converted.
15    pub value: Spell,
16}
17
18impl fmt::Display for TryFromSpellError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        write!(f, "No value matching `{}` for attribute `{}`", self.value, self.defindex)
21    }
22}
23
24impl std::error::Error for TryFromSpellError {}
25
26/// An error inserting into an attribute set.
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
28pub enum InsertError {
29    /// The set was full.
30    Full,
31    /// The value already exists in the set.
32    Duplicate,
33}
34
35impl fmt::Display for InsertError {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        match self {
38            InsertError::Full => write!(f, "Attribute set is full"),
39            InsertError::Duplicate => write!(f, "Attribute already exists in set"),
40        }
41    }
42}
43
44impl std::error::Error for InsertError {}