From: Ian Jackson Date: Fri, 23 Jul 2021 21:23:30 +0000 (+0100) Subject: wip parsing, shuffle X-Git-Tag: hippotat/1.0.0~516 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=acf7d69171f66f87b6ea66749e0d58d6c401989f;p=hippotat.git wip parsing, shuffle Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index 64e2451..e5c06cb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -57,6 +57,16 @@ pub struct InstanceConfig { pub vroutes: Vec, } +#[derive(Debug,Clone)] +pub enum SectionName { + Link { server: ServerName, client: ClientName }, + Client(ClientName), + Server(ServerName), // includes SERVER, which is slightly special + Common, + Default, +} +pub use SectionName as SN; + type SectionMap = HashMap>; pub struct Config { @@ -81,6 +91,28 @@ impl<'f,A> OkAnyway<'f,A> { } } +impl FromStr for SectionName { + type Err = AE; + #[throws(AE)] + fn from_str(s: &str) -> Self { + match s { + "COMMON" => return SN::Common, + "DEFAULT" => return SN::Default, + _ => { } + }; + if let Ok(n@ ServerName(_)) = s.parse() { return SN::Server(n) } + 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 " + ))?; + let server = server.parse().context("server name in link section name")?; + let client = client.parse().context("client name in link section name")?; + SN::Link { server, client } + } +} + impl Aggregate { #[throws(AE)] // AE does not include path fn read_file(&mut self, path: &Path, anyway: OkAnyway) -> Option diff --git a/src/prelude.rs b/src/prelude.rs index b752627..18a4646 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -23,6 +23,7 @@ pub use void::{self, Void}; pub use crate::config; pub use crate::utils::*; +pub use crate::types::*; pub use anyhow::Error as AE; pub use ErrorKind as EK; diff --git a/src/types.rs b/src/types.rs index 38fcbfe..cf862d3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -10,16 +10,6 @@ pub struct ServerName(pub String); #[derive(Debug,Clone,Copy)] pub struct ClientName(pub Ipv4Addr); -#[derive(Debug,Clone)] -pub enum SectionName { - Link { server: ServerName, client: ClientName }, - Client(ClientName), - Server(ServerName), // includes SERVER, which is slightly special - Common, - Default, -} -pub use SectionName as SN; - impl FromStr for ClientName { type Err = AE; #[throws(AE)] @@ -51,25 +41,3 @@ impl FromStr for ServerName { ServerName(s.into()) } } - -impl FromStr for SectionName { - type Err = AE; - #[throws(AE)] - fn from_str(s: &str) -> Self { - match s { - "COMMON" => return SN::Common, - "DEFAULT" => return SN::Default, - _ => { } - }; - if let Ok(n@ ServerName(_)) = s.parse() { return SN::Server(n) } - 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 " - ))?; - let server = server.parse().context("server name in link section name")?; - let client = client.parse().context("client name in link section name")?; - SN::Link { server, client } - } -}