chiark / gitweb /
config: better display
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 18:49:13 +0000 (19:49 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 18:49:13 +0000 (19:49 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/config.rs
src/prelude.rs
src/types.rs

index 4607eb676fec37dc6576b51d1793118dd5ff73f9..c650646520208d7aff30a2e06fa59705a1b0cb7a 100644 (file)
@@ -139,7 +139,7 @@ impl<'v> RawValRef<'v,'_,'_> {
   fn try_map<F,T>(&self, f: F) -> T
   where F: FnOnce(Option<&'v str>) -> Result<T, AE> {
     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<InstanceConfig> {
     };
 
     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);
   }
index b46e2d95a904aa10d8b8d2db80ab5a6707900d89..7b02ea009896c1e770ac7c9820e0e7c1649d5180 100644 (file)
@@ -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};
index 07f6ecb7d5fae2baa41493455b480f1ab13018c3..578671531359085753e15eeac49c973602f631f6 100644 (file)
@@ -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)?;
+  }
+}