Skip to content

Commit

Permalink
Implement Add for Generation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ecton committed Nov 28, 2024
1 parent 66d37cb commit f39a4e1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>`.
pub trait IntoReadOnly<T> {
/// Returns `self` as a `ReadOnly`.
Expand Down

0 comments on commit f39a4e1

Please sign in to comment.