use std::error::Error;
use std::fmt::{self, Display};
#[derive(Debug)]
pub struct UnsafeInterval<T> {
unit: &'static str,
interval: T,
}
impl<T> UnsafeInterval<T> {
#[inline]
pub const fn new(unit: &'static str, interval: T) -> Self {
Self { unit, interval }
}
}
impl<T> Display for UnsafeInterval<T>
where
T: Display,
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "invalid {} per second: {}", self.unit, self.interval)
}
}
impl<T> Error for UnsafeInterval<T> where T: fmt::Debug + Display {}
#[derive(Debug)]
pub enum ColorFromStrErr {
UnknownColor(String),
InvalidHex(String),
}
impl ColorFromStrErr {
pub fn invalid_hex<S>(hex: S) -> Self
where
S: Into<String>,
{
Self::InvalidHex(hex.into())
}
}
impl Display for ColorFromStrErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownColor(s) => write!(f, "unknown color: {s}"),
Self::InvalidHex(s) => write!(f, "invalid hex code: {s}"),
}
}
}
impl Error for ColorFromStrErr {}