ansi_color_codec/
error.rs1use core::fmt::{self, Display, Formatter};
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5pub enum Error {
6 ByteStreamTerminatedUnexpectedly,
8 InvalidCodeValue,
10 InvalidNumberPrefix(u8),
12 InvalidStartByte(u8),
14 MissingSecondColorCodeBlock,
16 NoCodeDigitsFound,
18 TooManyCodeDigits {
20 at_least: u8,
22 max: u8,
24 },
25 UnexpectedByte(u8),
27 ValueOutOfBounds(u8),
29}
30
31impl Display for Error {
32 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
33 match self {
34 Self::ByteStreamTerminatedUnexpectedly => {
35 write!(f, "byte stream terminated unexpectedly")
36 }
37 Self::InvalidCodeValue => write!(f, "invalid code value"),
38 Self::InvalidNumberPrefix(prefix) => write!(f, "invalid number prefix: {prefix}"),
39 Self::InvalidStartByte(byte) => write!(f, "invalid start byte: {byte:?}"),
40 Self::MissingSecondColorCodeBlock => write!(f, "missing second code block"),
41 Self::NoCodeDigitsFound => write!(f, "no code digits found"),
42 Self::TooManyCodeDigits { at_least, max } => {
43 write!(f, "too many code digits found: {at_least}+ / {max}")
44 }
45 Self::UnexpectedByte(byte) => write!(f, "unexpected byte: {byte:?}"),
46 Self::ValueOutOfBounds(value) => write!(f, "value out of bounds: {value}"),
47 }
48 }
49}
50
51impl core::error::Error for Error {}