use super::Time; use core::fmt::{Display, Error, Formatter}; #[derive(Debug, Clone, Copy)] #[repr(transparent)] pub struct Kilosecond(usize); impl Display for Kilosecond { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { let mut reg = self.0; let mut buf = [0u8, 0, 0, 0, 0]; let mut n = 0; while n < 8 { if n > 2 { buf[7 - n] = match reg % 10 { 0 => b'0', 1 => b'1', 2 => b'2', 3 => b'3', 4 => b'4', 5 => b'5', 6 => b'6', 7 => b'7', 8 => b'8', 9 => b'9', _ => unreachable!["CPU is borken"], }; } reg /= 10; n += 1; } for (n, b) in buf.iter().enumerate() { write![f, "{}", *b as char]?; if n == 1 { write![f, "."]?; } } Ok(()) } } impl core::ops::Add for Kilosecond { type Output = Self; fn add(self, rhs: Self) -> Self { Self(self.0 + rhs.0) } } impl core::ops::Sub for Kilosecond { type Output = Self; fn sub(self, rhs: Self) -> Self { Self(self.0 - rhs.0) } } impl From