1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use std::num::ParseIntError;

/// Errors that can occur when converting an ANSI string to HTML
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// Parsing a number was unsuccessful
    #[error(transparent)]
    ParseInt(#[from] ParseIntError),

    /// The ANSI escape code is invalid
    #[error("Invalid ANSI: {msg}")]
    InvalidAnsi { msg: String },
}

impl Error {
    pub(crate) fn invalid_ansi(s: &'static str) -> impl Fn() -> Self {
        move || Error::InvalidAnsi { msg: s.to_string() }
    }
}