1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
pub static DEFAULT_METRICS: DefaultMetrics = DefaultMetrics::new();
pub trait Metrics {
fn char_width(&self, c: char) -> usize;
fn tab_stop(&self) -> usize;
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct DefaultMetrics {
tab_stop: usize,
}
impl DefaultMetrics {
pub const fn new() -> DefaultMetrics { Self::with_tab_stop(8) }
pub const fn with_tab_stop(tab_stop: usize) -> DefaultMetrics { DefaultMetrics { tab_stop } }
}
impl Metrics for DefaultMetrics {
fn char_width(&self, c: char) -> usize {
match c {
'\r' | '\n' => 0,
_ => 1,
}
}
fn tab_stop(&self) -> usize { self.tab_stop }
}