Skip to main content

vuquest_3320/
result.rs

1use core::fmt;
2
3/// Convenience alias for the library [Result](std::result::Result) type.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// Represents error conditions for the library.
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum Error {
9    InvalidVariant,
10    InvalidValue(usize),
11}
12
13impl Error {
14    /// Creates a new [Error].
15    pub const fn new() -> Self {
16        Self::InvalidVariant
17    }
18}
19
20impl Default for Error {
21    fn default() -> Self {
22        Self::new()
23    }
24}
25
26impl fmt::Display for Error {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            Self::InvalidVariant => write!(f, "invalid variant"),
30            Self::InvalidValue(err) => write!(f, "invalid value: {err}"),
31        }
32    }
33}
34
35impl core::error::Error for Error {}