From f39a4e17c8278b473323c4910d878b11389fe0c3 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Thu, 28 Nov 2024 10:02:06 -0800 Subject: [PATCH] Implement Add for Generation Given the incrementing nature of Generation, adding two generations together and comparing the results of doing the same with a potentially updated pair of generations will always be not-equal if either or both change with the only edge case being if the total changes exactly equals usize::MAX. Thus this can be used to combine knowledge of multiple generations into a single generation safely. --- src/value.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/value.rs b/src/value.rs index a150fe636..0c8b4c24e 100644 --- a/src/value.rs +++ b/src/value.rs @@ -2622,6 +2622,14 @@ impl Generation { } } +impl Add for Generation { + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output { + Self(self.0.wrapping_add(rhs.0)) + } +} + /// A type that can convert into a `ReadOnly`. pub trait IntoReadOnly { /// Returns `self` as a `ReadOnly`.