use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
UnknownFamily {
family: String,
},
UnknownVariant {
family: String,
variant: String,
},
InvalidPaletteSpec {
spec: String,
},
InvalidHexColor {
input: String,
},
InvalidAlpha {
alpha: f32,
},
TooManyColorsRequested {
family: &'static str,
variant: &'static str,
requested: usize,
available: usize,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownFamily { family } => {
write!(f, "unknown ggsci palette family `{family}`")
}
Self::UnknownVariant { family, variant } => {
write!(f, "unknown ggsci palette variant `{variant}` for family `{family}`")
}
Self::InvalidPaletteSpec { spec } => {
write!(f, "invalid palette spec `{spec}`; expected `family:variant`")
}
Self::InvalidHexColor { input } => {
write!(f, "invalid hex color `{input}`; expected `#RRGGBB`")
}
Self::InvalidAlpha { alpha } => {
write!(f, "invalid alpha `{alpha}`; expected a finite value in 0.0..=1.0")
}
Self::TooManyColorsRequested {
family,
variant,
requested,
available,
} => write!(
f,
"requested {requested} colors from `{family}:{variant}`, but only {available} are available"
),
}
}
}
impl std::error::Error for Error {}