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(())