use std::ops::RangeInclusive;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Heads {
last: Option<u64>,
}
impl Heads {
#[must_use]
pub const fn new() -> Heads {
Heads { last: None }
}
#[must_use]
pub const fn after(last: u64) -> Heads {
Heads { last: Some(last) }
}
#[must_use]
pub const fn last(&self) -> Option<u64> {
self.last
}
pub fn seen(&mut self, head: u64) -> Option<RangeInclusive<u64>> {
let first = match self.last {
None => head,
Some(last) if head > last => last + 1,
Some(_) => return None,
};
self.last = Some(head);
Some(first..=head)
}
}
#[cfg(test)]
#[path = "tests/heads.rs"]
mod tests;