| 1 | use core::error::Error; |
| 2 | use core::fmt; |
| 3 | |
| 4 | /// An error which can be returned when parsing a CSS color string. |
| 5 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 6 | pub enum ParseColorError { |
| 7 | /// A CSS color string was invalid hex format. |
| 8 | InvalidHex, |
| 9 | /// A CSS color string was invalid rgb format. |
| 10 | InvalidRgb, |
| 11 | /// A CSS color string was invalid hsl format. |
| 12 | InvalidHsl, |
| 13 | /// A CSS color string was invalid hwb format. |
| 14 | InvalidHwb, |
| 15 | /// A CSS color string was invalid hsv format. |
| 16 | InvalidHsv, |
| 17 | /// A CSS color string was invalid lab format. |
| 18 | InvalidLab, |
| 19 | /// A CSS color string was invalid lch format. |
| 20 | InvalidLch, |
| 21 | /// A CSS color string was invalid oklab format. |
| 22 | InvalidOklab, |
| 23 | /// A CSS color string was invalid oklch format. |
| 24 | InvalidOklch, |
| 25 | /// A CSS color string was invalid color function. |
| 26 | InvalidFunction, |
| 27 | /// A CSS color string was invalid unknown format. |
| 28 | InvalidUnknown, |
| 29 | } |
| 30 | |
| 31 | impl fmt::Display for ParseColorError { |
| 32 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 33 | match *self { |
| 34 | Self::InvalidHex => f.write_str("invalid hex format"), |
| 35 | Self::InvalidRgb => f.write_str("invalid rgb format"), |
| 36 | Self::InvalidHsl => f.write_str("invalid hsl format"), |
| 37 | Self::InvalidHwb => f.write_str("invalid hwb format"), |
| 38 | Self::InvalidHsv => f.write_str("invalid hsv format"), |
| 39 | Self::InvalidLab => f.write_str("invalid lab format"), |
| 40 | Self::InvalidLch => f.write_str("invalid lch format"), |
| 41 | Self::InvalidOklab => f.write_str("invalid oklab format"), |
| 42 | Self::InvalidOklch => f.write_str("invalid oklch format"), |
| 43 | Self::InvalidFunction => f.write_str("invalid color function"), |
| 44 | Self::InvalidUnknown => f.write_str("invalid unknown format"), |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl Error for ParseColorError {} |