tf2_enum/
error.rs

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