diff --git a/src/main.rs b/src/main.rs index e206407..3088ce7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use serde::Deserialize; -use std::{env,fs::File}; +use std::{env,fmt,fs::File}; use std::io::BufReader; use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; @@ -48,6 +48,17 @@ struct PortRegistration { service: Option, } +impl fmt::Display for PortRegistration { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"", + self.file.display(), self.job, self.group, self.task, + match &self.service { + None => "", + Some(s) => s + }) + } +} + impl Ctx { pub fn new() -> Self { Ctx { ports: HashMap::new() } @@ -138,12 +149,7 @@ fn main() -> Result { have_conflicts = true; println!("Conflict in site {}, port {:?}:", &datacenter, port); for reg in ®s { - println!("- in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"", - reg.file.display(), reg.job, reg.group, reg.task, - match ®.service { - None => "", - Some(s) => s - }) + println!("- {}", reg) } println!() }