1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use std::fmt; #[derive(Clone, Debug, Default)] pub struct CheckmarkItem<'a> { pub checked: bool, pub text: &'a str, } impl<'a> CheckmarkItem<'a> { pub fn new() -> Self { Self::default() } pub fn from(text: &'a str, checked: bool) -> Self { Self { text, checked } } } impl fmt::Display for CheckmarkItem<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let checkmark = if self.checked { "x" } else { " " }; write!(f, "[{}] {}", checkmark, self.text) } } pub trait Strikethrough { fn strikethrough(&self) -> String; } impl<T> Strikethrough for T where T: AsRef<str> { fn strikethrough(&self) -> String { format!("~{}~", self.as_ref()) } }