Panic on an attempt of subtracting sequence numbers with underflow.

This would result in results near usize::MAX, and is indicative of
a bug. A panic is always used instead of a debug_assert!() because
debug builds are easily slow enough so that the underlying bugs
are not tripped.

Related to #62.
This commit is contained in:
whitequark 2017-12-21 12:33:32 +00:00
parent bd40265d3a
commit 3029341d5a
1 changed files with 5 additions and 1 deletions

View File

@ -51,7 +51,11 @@ impl ops::Sub for SeqNumber {
type Output = usize;
fn sub(self, rhs: SeqNumber) -> usize {
self.0.wrapping_sub(rhs.0) as usize
let result = self.0.wrapping_sub(rhs.0);
if result < 0 {
panic!("attempt to subtract sequence numbers with underflow")
}
result as usize
}
}