#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GlassTintAmount(f32);
#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
#[error("glass tint amount must be finite and between 0 and 100 percent")]
pub struct InvalidGlassTintAmount;
impl GlassTintAmount {
pub fn from_percent(percent: f32) -> Result<Self, InvalidGlassTintAmount> {
if percent.is_finite() && (0.0..=100.0).contains(&percent) {
Ok(Self(percent))
} else {
Err(InvalidGlassTintAmount)
}
}
pub fn percent(self) -> f32 {
self.0
}
}
impl Default for GlassTintAmount {
fn default() -> Self {
Self(25.0)
}
}
#[cfg(test)]
#[path = "tests/appearance_tests.rs"]
mod tests;