tabled/settings/peaker/
none.rs

1use super::Peaker;
2
3/// A Peaker which goes over column 1 by 1.
4#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash)]
5pub struct PriorityNone {
6    i: usize,
7}
8
9impl PriorityNone {
10    /// Creates a new priority which does not target anything.
11    pub const fn new() -> Self {
12        Self { i: 0 }
13    }
14}
15
16impl Peaker for PriorityNone {
17    fn peak(&mut self, _: &[usize], widths: &[usize]) -> Option<usize> {
18        let mut i = self.i;
19        let mut count_empty = 0;
20        while widths[i] == 0 {
21            i += 1;
22            if i >= widths.len() {
23                i = 0;
24            }
25
26            count_empty += 1;
27            if count_empty == widths.len() {
28                return None;
29            }
30        }
31
32        let col = i;
33
34        i += 1;
35        if i >= widths.len() {
36            i = 0;
37        }
38
39        self.i = i;
40
41        Some(col)
42    }
43}