diff --git a/src/main.rs b/src/main.rs index 0180ddb..c529916 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use std::fmt; use std::collections::HashMap; +use std::fmt; // Structure of a notification struct Notif { @@ -16,26 +16,26 @@ struct Notif { // Function to print the contents of the notification impl fmt::Display for Notif { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f,"AppName: {}\n", &self.app_name)?; + writeln!(f, "AppName: {}", &self.app_name)?; match self.replace_id { - Some(notif_id) => write!(f, "ReplaceId: {}\n", notif_id)?, - None => write!(f, "None\n")?, + Some(notif_id) => writeln!(f, "ReplaceId: {notif_id}")?, + None => writeln!(f, "None")?, } - write!(f,"Icon: {}\nSummary: {}\nBody: {}\nActions:\n", - &self.ico, - &self.summary, - &self.body + write!( + f, + "Icon: {}\nSummary: {}\nBody: {}\nActions:\n", + &self.ico, &self.summary, &self.body )?; for (key, label) in &self.actions { - write!(f, "\t{}: {}\n", key, label)?; + writeln!(f, "\t{key}: {label}")?; } - write!(f,"Hints:\n")?; + writeln!(f, "Hints:")?; for (key, value) in &self.hints { - write!(f, "\t{}: {}\n", key, value)?; + writeln!(f, "\t{key}: {value}")?; } match self.expir_timeout { - Some(millisec) => write!(f, "Expiration Timeout: {}\n", millisec)?, - None => write!(f, "None\n")?, + Some(millisec) => writeln!(f, "Expiration Timeout: {millisec}")?, + None => writeln!(f, "None")?, } Ok(()) // Return Ok to indicate success } @@ -45,7 +45,7 @@ impl fmt::Display for Notif { fn truncate_summary(notif: &mut Notif) { if notif.summary.len() > 40 { notif.summary.truncate(39); - notif.summary.push_str("…"); + notif.summary.push('…'); } } @@ -62,12 +62,14 @@ fn main() { ("close".to_string(), "Close".to_string()), ], hints: HashMap::new(), // Create an empty HashMap for hints, add the hints later - expir_timeout: Some(0) + expir_timeout: Some(0), }; - not.hints.insert("urgency".to_string(), "critical".to_string()); - not.hints.insert("category".to_string(), "network.error".to_string()); - + not.hints + .insert("urgency".to_string(), "critical".to_string()); + not.hints + .insert("category".to_string(), "network.error".to_string()); + truncate_summary(&mut not); //Limit the summary length - - println!("{}", not); + + println!("{not}"); }