From: Ian Jackson Date: Sat, 15 May 2021 12:18:27 +0000 (+0100) Subject: Provide .is_empty() for many types X-Git-Tag: otter-0.6.0~291 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=40f84ff94de8e3c854bd4df41e1e168c6368690f;p=otter.git Provide .is_empty() for many types Clearing bundles is going to want to check this. Signed-off-by: Ian Jackson --- diff --git a/src/global.rs b/src/global.rs index 4ab5b9cb..a9eb8b8f 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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 ---------- diff --git a/src/hidden.rs b/src/hidden.rs index 31f165bd..b62d31e0 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -268,6 +268,11 @@ impl GameOccults { } }) } + + pub fn is_empty(&self) -> bool { + let GameOccults { occults } = self; + occults.is_empty() + } } // ========== public entrypoints ========== diff --git a/src/occultilks.rs b/src/occultilks.rs index 7bf9fc9b..5bd9afad 100644 --- a/src/occultilks.rs +++ b/src/occultilks.rs @@ -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 for OId { fn borrow(&self) -> &Id { &self.0 } } + +impl IOccults { + pub fn is_empty(&self) -> bool { + let IOccults { ilks } = self; + ilks.is_empty() + } +} diff --git a/src/pcaliases.rs b/src/pcaliases.rs index 26cb29d4..9ef363a4 100644 --- a/src/pcaliases.rs +++ b/src/pcaliases.rs @@ -24,6 +24,11 @@ impl PieceAliases { pub fn keys(&self) -> impl Iterator { self.map.keys() } + + pub fn is_empty(&self) -> bool { + let PieceAliases { map } = self; + map.is_empty() + } } #[derive(Debug,Clone,Serialize,Deserialize)]