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:
parent
bd40265d3a
commit
3029341d5a
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue