Skip to main content

tui/tabs/
seq.rs

1//! The id counter of a window's requests: only the latest one is awaited.
2
3#[derive(Clone, Copy, Debug, Default)]
4pub struct Seq(u64);
5
6impl Seq {
7    /// Starts a request; an older one stops being awaited.
8    pub fn advance(&mut self) -> u64 {
9        self.0 = self.0.wrapping_add(1);
10        self.0
11    }
12
13    #[must_use]
14    pub fn current(&self) -> u64 {
15        self.0
16    }
17
18    #[must_use]
19    pub fn awaits(&self, id: u64) -> bool {
20        self.0 == id
21    }
22}
23
24#[cfg(test)]
25mod tests;