From b792cd13e5b90022d4636f07029242442f8e52f0 Mon Sep 17 00:00:00 2001 From: candifloss Date: Tue, 20 Aug 2024 10:26:36 +0530 Subject: [PATCH] cargo fmt & corrections --- src/main.rs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) 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}"); }