Make sequences wrap around to avoid overflows

Instead of aborting with an `attempt to add with overflow` error, wrap the sequence around so that it goes back to 0 once it has reached the maximum value for the integer type.  Fixes #437.
This commit is contained in:
Adam Nielsen 2020-02-23 11:27:38 +10:00 committed by GitHub
parent 08c239319c
commit 036f1f7cec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,7 +38,7 @@ pub trait Seq {
macro_rules! impl_seq { macro_rules! impl_seq {
($($ty:ty)*) => { $( ($($ty:ty)*) => { $(
impl Seq for $ty { impl Seq for $ty {
fn next(&self) -> Self { *self + 1 } fn next(&self) -> Self { (*self).wrapping_add(1) }
} }
)* } )* }
} }