chiark / gitweb /
Break out UniqueGenGen into gamestate
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Mar 2021 19:45:32 +0000 (19:45 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Mar 2021 19:45:32 +0000 (19:45 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
src/hidden.rs

index 4d56fcfe5644195a3961a56807715dbb8f8ed1e7..10bbe91ecb70c653937228f1e5bded337256b005 100644 (file)
@@ -197,6 +197,9 @@ pub trait PieceSpec: Debug {
 
 impl Generation {
   pub fn increment(&mut self) { self.0 += 1 }
+  pub fn unique_gen(&mut self) -> UniqueGenGen<'_> {
+    UniqueGenGen { gen: self, none_yet: iter::once(()) }
+  }
 }
 impl Display for Generation {
   fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
@@ -204,6 +207,20 @@ impl Display for Generation {
   }
 }
 
+pub struct UniqueGenGen<'g> {
+  gen: &'g mut Generation,
+  none_yet: iter::Once<()>,
+}
+
+impl UniqueGenGen<'_> {
+  pub fn next(&mut self) -> Generation {
+    if self.none_yet.next().is_some() { self.gen.increment() }
+    let r = *self.gen;
+    self.gen.increment();
+    r
+  }
+}
+
 impl Timestamp {
   /// Always >= previously
   pub fn now() -> Timestamp {
index 15e5499256d00050057c1e2b4f13d7da1c24dc42..57a2e1d7b9dc38035850ee068ebe4e2d5b0d1bba 100644 (file)
@@ -860,16 +860,7 @@ mod recompute {
                      gpieces: &mut GPieces,
                      goccults: &mut GameOccults,
                      ipieces: &IPieces) -> Implemented {
-      struct GenIncr<'g> { gen: &'g mut Generation, none_yet: iter::Once<()>, }
-      impl GenIncr<'_> {
-        fn next(&mut self) -> Generation {
-          if self.none_yet.next().is_some() { self.gen.increment() }
-          let r = *self.gen;
-          self.gen.increment();
-          r
-        }
-      }
-      let mut gen = GenIncr { gen, none_yet: iter::once(()) };
+      let mut gen = gen.unique_gen();
 
       for occid in self.outdated {
         if let Some(occ) = goccults.occults.get_mut(occid) {