cranpose_liquid/
appearance.rs1#[derive(Clone, Copy, Debug, PartialEq)]
5pub struct GlassTintAmount(f32);
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
9#[error("glass tint amount must be finite and between 0 and 100 percent")]
10pub struct InvalidGlassTintAmount;
11
12impl GlassTintAmount {
13 pub fn from_percent(percent: f32) -> Result<Self, InvalidGlassTintAmount> {
15 if percent.is_finite() && (0.0..=100.0).contains(&percent) {
16 Ok(Self(percent))
17 } else {
18 Err(InvalidGlassTintAmount)
19 }
20 }
21
22 pub fn percent(self) -> f32 {
24 self.0
25 }
26}
27
28impl Default for GlassTintAmount {
29 fn default() -> Self {
30 Self(25.0)
31 }
32}
33
34#[cfg(test)]
35#[path = "tests/appearance_tests.rs"]
36mod tests;