token_read/count.rs
1/// A trait for various types than can represent a number of lines.
2///
3/// Implementations are provided for all base unsigned integers.
4pub trait LineCount {
5 /// Lower the number by one.
6 fn decrement(&mut self);
7 /// Check whether the number is equal to zero.
8 fn empty(&self) -> bool;
9}
10
11macro_rules! impl_uint {
12 ($t: ty) => {
13 impl LineCount for $t {
14 fn decrement(&mut self) {
15 *self = self.saturating_sub(1)
16 }
17
18 fn empty(&self) -> bool {
19 *self == 0
20 }
21 }
22 };
23}
24
25impl_uint!(u8);
26impl_uint!(u16);
27impl_uint!(u32);
28impl_uint!(u64);
29impl_uint!(u128);
30impl_uint!(usize);