1use std::{fmt, num::ParseIntError};
2
3#[derive(Debug)]
5pub enum Error {
6 ParseInt(ParseIntError),
8
9 InvalidAnsi { msg: String },
11}
12
13impl From<ParseIntError> for Error {
14 fn from(err: ParseIntError) -> Self {
15 Self::ParseInt(err)
16 }
17}
18
19impl fmt::Display for Error {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Self::ParseInt(err) => write!(f, "{err}"),
23 Self::InvalidAnsi { msg } => write!(f, "Invalid ANSI: {msg}"),
24 }
25 }
26}
27
28impl std::error::Error for Error {}
29
30impl Error {
31 pub(crate) fn invalid_ansi(s: &'static str) -> impl Fn() -> Self {
32 move || Error::InvalidAnsi { msg: s.to_string() }
33 }
34}