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

index 64e2451bcbaca7abd12cc1f8c7a30eb2105aae2d..e5c06cbbd6436ca9405de4450efe52aef1070138 100644 (file)
@@ -57,6 +57,16 @@ pub struct InstanceConfig {
   pub vroutes:                      Vec<CidrString>,
 }
 
+#[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<String, Option<String>>;
 
 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, <server>, <client>, or <server> <client>"
+      ))?;
+    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<A>(&mut self, path: &Path, anyway: OkAnyway<A>) -> Option<A>
index b75262774cc43193808b9bd22be3643661b424a9..18a4646bad85196e0cf1f9e334b5de0f68c622f7 100644 (file)
@@ -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;
index 38fcbfec452ca6678aa97c9733fddf2d338abc31..cf862d3999bef334cb8a32c8180987f8139c76ad 100644 (file)
@@ -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, <server>, <client>, or <server> <client>"
-      ))?;
-    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 }
-  }
-}