chiark / gitweb /
wip parsing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 23 Jul 2021 22:10:33 +0000 (23:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 23 Jul 2021 22:10:33 +0000 (23:10 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/config.rs
src/types.rs

index 58ffd6cbdf4f89ce79abf1fffa096fef6ec354b2..98d67ed07bd6a821b2a665bca6c1a723d013babf 100644 (file)
@@ -57,7 +57,7 @@ pub struct InstanceConfig {
   pub vroutes:                      Vec<CidrString>,
 }
 
-#[derive(Debug,Clone)]
+#[derive(Debug,Clone,Hash,Eq,PartialEq)]
 pub enum SectionName {
   Link { server: ServerName, client: ClientName },
   Client(ClientName),
@@ -67,7 +67,7 @@ pub enum SectionName {
 }
 pub use SectionName as SN;
 
-type SectionMap = HashMap<SectionName, Option<String>>;
+type SectionMap = HashMap<String, Option<String>>;
 
 pub struct Config {
   opts: Opts,
@@ -77,7 +77,7 @@ static OUTSIDE_SECTION: &str = "[";
 
 #[derive(Default,Debug)]
 struct Aggregate {
-  sections: HashMap<String, SectionMap>,
+  sections: HashMap<SectionName, SectionMap>,
 }
 
 type OkAnyway<'f,A> = &'f dyn Fn(ErrorKind) -> Option<A>;
@@ -104,8 +104,9 @@ impl FromStr for SectionName {
     if let Ok(n@ ClientName(_)) = s.parse() { return SN::Client(n) }
     let (server, client) = s.split_ascii_whitespace().collect_tuple()
       .ok_or_else(|| anyhow!(
-        "bad section name \
-         (must be COMMON, DEFAULT, <server>, <client>, or <server> <client>"
+        "bad section name {:?} \
+         (must be COMMON, DEFAULT, <server>, <client>, or <server> <client>",
+        s
       ))?;
     let server = server.parse().context("server name in link section name")?;
     let client = client.parse().context("client name in link section name")?;
@@ -139,9 +140,10 @@ impl Aggregate {
 
     for (sn, vars) in map.drain() {
       let sn = sn.parse().dcontext(&sn)?;
+      Extend::extend(
       self.sections.entry(sn)
-        .or_default()
-        .extend(vars);
+        .or_default(),
+        vars);
     }
     None
   }
index cf862d3999bef334cb8a32c8180987f8139c76ad..ecfb68ac65e6783f49c6ba7e7e5cacdb11058fd6 100644 (file)
@@ -4,10 +4,10 @@
 
 use crate::prelude::*;
 
-#[derive(Debug,Clone)]
+#[derive(Debug,Clone,Hash,Eq,PartialEq)]
 pub struct ServerName(pub String);
 
-#[derive(Debug,Clone,Copy)]
+#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
 pub struct ClientName(pub Ipv4Addr);
 
 impl FromStr for ClientName {