1#[derive(Debug, Clone)]
2pub struct UnitTool;
3
4impl UnitTool {
5 pub fn new() -> Self { Self }
6
7 pub fn bytes_to_kb(&self, bytes: u64) -> f64 { bytes as f64 / 1024.0 }
8 pub fn bytes_to_mb(&self, bytes: u64) -> f64 { bytes as f64 / 1024.0 / 1024.0 }
9 pub fn bytes_to_gb(&self, bytes: u64) -> f64 { bytes as f64 / 1024.0 / 1024.0 / 1024.0 }
10
11 pub fn c_to_f(&self, c: f64) -> f64 { c * 9.0 / 5.0 + 32.0 }
12 pub fn f_to_c(&self, f: f64) -> f64 { (f - 32.0) * 5.0 / 9.0 }
13}
14
15impl Default for UnitTool {
16 fn default() -> Self { Self::new() }
17}