initials_revamped/
error.rs

1//! Error module includes the custom error types.
2use std::num::ParseIntError;
3use std::io;
4
5/// Custom Error type for Avatar
6#[derive(Debug, Fail)]
7pub enum Error {
8    /// Invalid hex string
9    #[fail(display = "unexpected hex color format: expected({}), got({})", expected, actual)]
10    InvalidHexFormat {
11        actual: String,
12        expected: String,
13    },
14    /// Parse error
15    #[fail(display = "couldn't parse hex value: {}", _0)]
16    Parse(ParseIntError),
17    /// IO read/write error
18    #[fail(display = "IO error: {}", _0)]
19    IO(io::Error)
20}
21
22impl From<ParseIntError> for Error {
23    fn from(error: ParseIntError) -> Self {
24        Error::Parse(error)
25    }
26}
27
28impl From<io::Error> for Error {
29    fn from(error: io::Error) -> Self {
30        Error::IO(error)
31    }
32}