make pdu batch tokens zeroith-indexed

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-06 22:21:51 +00:00
parent f36757027e
commit e507c31306
9 changed files with 67 additions and 52 deletions

View file

@ -2,6 +2,8 @@
use std::{cmp::Ordering, fmt, fmt::Display, str::FromStr};
use ruma::api::Direction;
use crate::{err, Error, Result};
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
@ -54,6 +56,14 @@ impl PduCount {
}
}
#[inline]
pub fn checked_inc(self, dir: Direction) -> Result<Self, Error> {
match dir {
Direction::Forward => self.checked_add(1),
Direction::Backward => self.checked_sub(1),
}
}
#[inline]
pub fn checked_add(self, add: u64) -> Result<Self, Error> {
Ok(match self {
@ -82,6 +92,15 @@ impl PduCount {
})
}
#[inline]
#[must_use]
pub fn saturating_inc(self, dir: Direction) -> Self {
match dir {
Direction::Forward => self.saturating_add(1),
Direction::Backward => self.saturating_sub(1),
}
}
#[inline]
#[must_use]
pub fn saturating_add(self, add: u64) -> Self {