chiark / gitweb /
Provide .is_empty() for many types
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 May 2021 12:18:27 +0000 (13:18 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 May 2021 15:18:25 +0000 (16:18 +0100)
Clearing bundles is going to want to check this.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/global.rs
src/hidden.rs
src/occultilks.rs
src/pcaliases.rs

index 4ab5b9cb972dd73ac3f2b3f62c6646941030e118..a9eb8b8f5c517210317eb7cac54b4ee07e51915c 100644 (file)
@@ -1372,6 +1372,11 @@ impl IPieces {
   pub fn as_mut(&mut self, _: ModifyingPieces) -> &mut ActualIPieces {
     &mut self.0
   }
+
+  pub fn is_empty(&self) -> bool {
+    let  IPieces(actual) = self;
+    actual.is_empty()
+  }
 }
 
 // ---------- gamestate pieces table ----------
index 31f165bd46715f44ed12a64d98b4c57dacb6b81d..b62d31e0c80eb58eb28b312e270968d3a1bd4199 100644 (file)
@@ -268,6 +268,11 @@ impl GameOccults {
       }
     })
   }
+
+  pub fn is_empty(&self) -> bool {
+    let GameOccults { occults } = self;
+    occults.is_empty()
+  }
 }
 
 // ========== public entrypoints ==========
index 7bf9fc9bcbeb57484328c66705aec4d0ef9dbe42..5bd9afad62348cc571ebd8fb3c10c07903f55e89 100644 (file)
@@ -71,8 +71,24 @@ impl OccultIlks {
       self.lookup.remove(&data.k);
     }
   }
+
+  pub fn is_empty(&self) -> bool {
+    let OccultIlks { lookup, table } = self;
+    #[allow(unused_parens)]
+    (
+         lookup.is_empty()
+      && table.is_empty()
+    )
+  }
 }
 
 impl Borrow<Id> for OId {
   fn borrow(&self) -> &Id { &self.0 }
 }
+
+impl IOccults {
+  pub fn is_empty(&self) -> bool {
+    let IOccults { ilks } = self;
+    ilks.is_empty()
+  }
+}
index 26cb29d48f7f8413280db6a66568d33c679ffd34..9ef363a427a9ec3a3049b2d4e2a052b6710a1f93 100644 (file)
@@ -24,6 +24,11 @@ impl PieceAliases {
   pub fn keys(&self) -> impl Iterator<Item=&String> {
     self.map.keys()
   }
+
+  pub fn is_empty(&self) -> bool {
+    let PieceAliases { map } = self;
+    map.is_empty()
+  }
 }
 
 #[derive(Debug,Clone,Serialize,Deserialize)]