}
}
impl PartialOrd for Sat {
fn partial_cmp(&self, other: &u64) -> Option {
self.0.partial_cmp(other)
}
}
impl Add for Sat {
type Output = Self;
fn add(self, other: u64) -> Sat {
Sat(self.0 + other)
}
}
impl AddAssign for Sat {
fn add_assign(&mut self, other: u64) {
*self = Sat(self.0 + other);
}
}
impl FromStr for Sat {
type Err = Error;
fn from_str(s: &str) -> Result {
if s.chars().any(|c| c.is_ascii_lowercase()) {
Self::from_name(s)
} else if s.contains('°') {
Self::from_degree(s)
} else if s.contains('%') {
Self::from_percentile(s)
} else if s.contains('.') {
Self::from_decimal(s)
} else {
let sat = Self(s.parse()?);
if sat > Self::LAST {
Err(anyhow!("invalid sat"))
} else {
Ok(sat)
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn n() {
assert_eq!(Sat(1).n(), 1);
assert_eq!(Sat(100).n(), 100);
}
#[test]
fn height() {