From: Ian Jackson Date: Sat, 24 Jul 2021 18:49:13 +0000 (+0100) Subject: config: better display X-Git-Tag: hippotat/1.0.0~459 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=7fa97278038634f7938f0c11dbb1d7c4731eeb9a;p=hippotat.git config: better display Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index 4607eb6..c650646 100644 --- a/src/config.rs +++ b/src/config.rs @@ -139,7 +139,7 @@ impl<'v> RawValRef<'v,'_,'_> { fn try_map(&self, f: F) -> T where F: FnOnce(Option<&'v str>) -> Result { f(self.raw) - .with_context(|| format!(r#"file {:?}, section "{:?}", key "{}""#, + .with_context(|| format!(r#"file {:?}, section {}, key "{}""#, self.loc, self.section, self.key))? } } @@ -190,6 +190,19 @@ impl FromStr for SectionName { SN::Link(LinkName { server, client }) } } +impl Display for SectionName { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { + match self { + SN::Link (ref l) => Display::fmt(l, f)?, + SN::Client(ref c) => write!(f, "[{}]" , c)?, + SN::Server(ref s) => write!(f, "[{}]" , s)?, + SN::ServerLimit(ref s) => write!(f, "[{} LIMIT] ", s)?, + SN::GlobalLimit => write!(f, "[LIMIT]" )?, + SN::Common => write!(f, "[COMMON]" )?, + } + } +} impl Aggregate { #[throws(AE)] // AE does not include path @@ -703,10 +716,10 @@ pub fn read(end: LinkEnd) -> Vec { }; let mut ic = InstanceConfig::resolve_instance(&rctx) - .with_context(|| format!(r#"resolve config for "{:?}""#, &link))?; + .with_context(|| format!("resolve config for {}", &link))?; ic.complete(end) - .with_context(|| format!(r#"complete config for "{:?}""#, &link))?; + .with_context(|| format!("complete config for {}", &link))?; ics.push(ic); } diff --git a/src/prelude.rs b/src/prelude.rs index b46e2d9..7b02ea0 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,7 +5,7 @@ pub use std::collections::{BTreeSet, HashMap}; pub use std::cmp::{min, max}; pub use std::fs; -pub use std::fmt::{self, Debug}; +pub use std::fmt::{self, Debug, Display}; pub use std::io::{self, ErrorKind, Read as _}; pub use std::mem; pub use std::net::{IpAddr, Ipv4Addr}; diff --git a/src/types.rs b/src/types.rs index 07f6ecb..5786715 100644 --- a/src/types.rs +++ b/src/types.rs @@ -50,3 +50,18 @@ impl FromStr for ServerName { ServerName(s.into()) } } + +impl Display for ServerName { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { Display::fmt(&self.0, f)?; } +} +impl Display for ClientName { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { Display::fmt(&self.0, f)?; } +} +impl Display for LinkName { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { + write!(f, "[{} {}]", &self.server, &self.client)?; + } +}