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> {
}
}
+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 {
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) {