diff options
Diffstat (limited to 'src/agenda.rs')
| -rw-r--r-- | src/agenda.rs | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/agenda.rs b/src/agenda.rs index dc57775..2543daa 100644 --- a/src/agenda.rs +++ b/src/agenda.rs @@ -1,11 +1,5 @@ -use serde::{ - Deserialize, - Serialize, -}; -use std::{ - fmt, - fs, -}; +use serde::{Deserialize, Serialize}; +use std::{fmt, fs}; use tokio::sync::mpsc; #[derive(Clone, Debug, Deserialize, Serialize)] @@ -33,9 +27,11 @@ pub struct Agenda { impl Agenda { fn write(&self) { - fs::write(std::path::Path::new("agenda.json"), - serde_json::to_string_pretty(&self).expect("Can't serialize agenda")) - .expect("Can't write agenda.json"); + fs::write( + std::path::Path::new("agenda.json"), + serde_json::to_string_pretty(&self).expect("Can't serialize agenda"), + ) + .expect("Can't write agenda.json"); } } @@ -49,8 +45,11 @@ pub fn parse_message<F>( message: &str, sender: &str, send_message: F, - point_sender: &mpsc::UnboundedSender<AgendaPoint> -) -> Option<Emoji> where F: FnOnce(String) { + point_sender: &mpsc::UnboundedSender<AgendaPoint>, +) -> Option<Emoji> +where + F: FnOnce(String), +{ if message.starts_with("!add ") { let mut agenda = read_agenda(); let agenda_point = AgendaPoint { @@ -63,20 +62,18 @@ pub fn parse_message<F>( Some(Emoji::Ok) } else if message.starts_with("!agenda") { let s = read_agenda() - .points - .iter() - .map(|p| p.to_string()) - .collect::<Vec<_>>() - .join("\n"); + .points + .iter() + .map(|p| p.to_string()) + .collect::<Vec<_>>() + .join("\n"); send_message(match s.as_str() { "" => "Agenda is empty".to_string(), - _ => s + _ => s, }); None } else if message.starts_with("!clear") { - Agenda { - points: Vec::new(), - }.write(); + Agenda { points: Vec::new() }.write(); Some(Emoji::Ok) } else if message.starts_with("!help") { send_message("Available commands:\n```!add -- Add something\n!agenda -- Print the agenda\n!clear -- Remove all items\n!help```".to_string()); @@ -90,7 +87,7 @@ pub fn parse_message<F>( fn read_agenda() -> Agenda { serde_json::from_str::<Agenda>( - &fs::read_to_string("agenda.json") - .expect("Can't read agenda.json")) - .expect("Error parsing agenda.json") + &fs::read_to_string("agenda.json").expect("Can't read agenda.json"), + ) + .expect("Error parsing agenda.json") } |
