chiark / gitweb /
config: Do not use Default for constructing Aggregate
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 18:07:48 +0000 (19:07 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 18:43:09 +0000 (19:43 +0100)
We are going to want to add a non-Default field, in a bit.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/config.rs

index 4e9c710ecc899b468f62963099e9d0dee8c5fd5d..f08fe71fe4a206cc1d942faf17cb6c4da4c45f61 100644 (file)
@@ -161,7 +161,7 @@ pub struct Config {
 static OUTSIDE_SECTION: &str = "[";
 static SPECIAL_SERVER_SECTION: &str = "SERVER";
 
-#[derive(Default,Debug)]
+#[derive(Debug)]
 struct Aggregate {
   keys_allowed: HashMap<&'static str, SectionKindList>,
   sections: HashMap<SectionName, SectionMap>,
@@ -221,6 +221,13 @@ impl Display for SectionName {
 }
 
 impl Aggregate {
+  fn new(
+    keys_allowed: HashMap<&'static str, SectionKindList>
+  ) -> Self { Aggregate {
+    keys_allowed,
+    sections: default(),
+  } }
+
   #[throws(AE)] // AE does not include path
   fn read_file<A>(&mut self, path: &Path, anyway: OkAnyway<A>) -> Option<A>
   {
@@ -804,9 +811,8 @@ impl InstanceConfig {
 #[throws(AE)]
 pub fn read(opts: &Opts, end: LinkEnd) -> Vec<InstanceConfig> {
   let agg = (||{
-    let mut agg = Aggregate::default();
-    agg.keys_allowed.extend(
-      InstanceConfig::FIELDS.iter().cloned()
+    let mut agg = Aggregate::new(
+      InstanceConfig::FIELDS.iter().cloned().collect(),
     );
 
     agg.read_string(DEFAULT_CONFIG.into(),