From 606b4de524d93656674b8f94817684b7129c7dc6 Mon Sep 17 00:00:00 2001 From: finga Date: Sun, 27 Jun 2021 02:58:56 +0200 Subject: [PATCH] Use a fn for verbose output when sending --- src/send.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/send.rs b/src/send.rs index 1e99346..835b677 100644 --- a/src/send.rs +++ b/src/send.rs @@ -26,6 +26,12 @@ pub struct Send { pub msg: String, } +fn print_verbose(verbose: bool, msg: &str, queue: &str) { + if verbose { + println!("Sent message: \"{}\" to queue: {}", &msg, &queue); + } +} + impl Send { pub fn run(&self, verbose: bool) -> Result<()> { let mq = &mut posixmq::OpenOptions::writeonly(); @@ -41,9 +47,7 @@ impl Send { *timeout.parse::()?, )?; - if verbose { - println!("Sent message: \"{}\" to queue: {}", &self.msg, &self.queue); - } + print_verbose(verbose, &self.msg, &self.queue); } else if let Some(deadline) = &self.deadline { mq.open(&self.queue)?.send_deadline( self.priority, @@ -51,16 +55,12 @@ impl Send { DateTime::parse_from_str(deadline, "%Y-%m-%d %H:%M:%S")?.into(), )?; - if verbose { - println!("Sent message: \"{}\" to queue: {}", &self.msg, &self.queue); - } + print_verbose(verbose, &self.msg, &self.queue); } else { mq.open(&self.queue)? .send(self.priority, &self.msg.as_bytes())?; - if verbose { - println!("Sent message: \"{}\" to queue: {}", &self.msg, &self.queue); - } + print_verbose(verbose, &self.msg, &self.queue); } Ok(())