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