From: Ian Jackson Date: Fri, 23 Jul 2021 22:10:33 +0000 (+0100) Subject: wip parsing X-Git-Tag: hippotat/1.0.0~514 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=93578eb4e93e5f2f6aea4dc429b404a47da96fba;p=hippotat.git wip parsing Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index 58ffd6c..98d67ed 100644 --- a/src/config.rs +++ b/src/config.rs @@ -57,7 +57,7 @@ pub struct InstanceConfig { pub vroutes: Vec, } -#[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>; +type SectionMap = HashMap>; pub struct Config { opts: Opts, @@ -77,7 +77,7 @@ static OUTSIDE_SECTION: &str = "["; #[derive(Default,Debug)] struct Aggregate { - sections: HashMap, + sections: HashMap, } type OkAnyway<'f,A> = &'f dyn Fn(ErrorKind) -> Option; @@ -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, , , or " + "bad section name {:?} \ + (must be COMMON, DEFAULT, , , or ", + 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 } diff --git a/src/types.rs b/src/types.rs index cf862d3..ecfb68a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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 {