add Display impl for printing PortRegistration

This commit is contained in:
Armaël Guéneau 2024-10-25 22:08:15 +02:00
parent 9cb4f6c11e
commit 734d97e191

View file

@ -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<String>,
}
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 => "<noname>",
Some(s) => s
})
}
}
impl Ctx {
pub fn new() -> Self {
Ctx { ports: HashMap::new() }
@ -138,12 +149,7 @@ fn main() -> Result<ExitCode> {
have_conflicts = true;
println!("Conflict in site {}, port {:?}:", &datacenter, port);
for reg in &regs {
println!("- in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"",
reg.file.display(), reg.job, reg.group, reg.task,
match &reg.service {
None => "<noname>",
Some(s) => s
})
println!("- {}", reg)
}
println!()
}