tabled/settings/peaker/
left.rs

1use super::Peaker;
2
3/// A Peaker which goes over column 1 by 1, but truncates as much as possible left side.
4#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash)]
5pub struct PriorityLeft {
6    i: usize,
7}
8
9impl PriorityLeft {
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 PriorityLeft {
17    fn peak(&mut self, min: &[usize], widths: &[usize]) -> Option<usize> {
18        let col = self.i;
19        if widths[col] > min[col] {
20            return Some(col);
21        }
22
23        if col + 1 == widths.len() {
24            return None;
25        }
26
27        let mut col = col + 1;
28        while widths[col] == min[col] {
29            if col + 1 == widths.len() {
30                return None;
31            }
32
33            col += 1;
34        }
35
36        Some(col)
37    }
38}