This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

1use itertools::Itertools; 2use std::collections::HashMap; 3use std::time::Duration; 4 5pub(crate) trait Pretty { 6 fn pretty(&self) -> String; 7} 8 9impl<K: std::fmt::Display> Pretty for HashMap<K, usize> { 10 fn pretty(&self) -> String { 11 self.iter() 12 .filter_map(|(name, &count)| { 13 if count > 0 { 14 Some(format!("{count} {name}")) 15 } else { 16 None 17 } 18 }) 19 .join(", ") 20 } 21} 22 23impl Pretty for Duration { 24 fn pretty(&self) -> String { 25 let (hours, rest) = self.as_millis().div_rem(&3_600_000); 26 let (minutes, rest) = rest.div_rem(&60_000); 27 let (seconds, milliseconds) = rest.div_rem(&1_000); 28 29 if hours > 0 { 30 format!("{} h {:02} m {:02} s", hours, minutes, seconds) 31 } else if minutes > 0 { 32 format!("{} m {:02} s", minutes, seconds) 33 } else if seconds > 0 { 34 format!("{}.{:03} s", seconds, milliseconds) 35 } else { 36 format!("{} ms", milliseconds) 37 } 38 } 39} 40 41trait DivRem<T> { 42 fn div_rem(&self, rhs: &T) -> (T, T); 43} 44 45impl DivRem<u128> for u128 { 46 fn div_rem(&self, rhs: &u128) -> (u128, u128) { 47 (self / rhs, self % rhs) 48 } 49} 50 51impl Pretty for std::path::PathBuf { 52 fn pretty(&self) -> String { 53 format!( 54 "{}{}", 55 if self.is_relative() { "./" } else { "" }, 56 self.to_string_lossy() 57 ) 58 } 59}