dia_args/docs/
cfg.rs

1/*
2==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
3
4Dia-Args
5
6Copyright (C) 2018-2019, 2021-2025  Anonymous
7
8There are several releases over multiple years,
9they are listed as ranges, such as: "2018-2019".
10
11This program is free software: you can redistribute it and/or modify
12it under the terms of the GNU Lesser General Public License as published by
13the Free Software Foundation, either version 3 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19GNU Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public License
22along with this program.  If not, see <https://www.gnu.org/licenses/>.
23
24::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
25*/
26
27//! # Configuration
28
29/// # Configuration
30///
31/// ## Default values
32///
33/// | Name       | Value
34/// | ---------- | -----
35/// | Tab length | `4`
36/// | Tab level  | `0`
37/// | Columns    | `128`
38#[derive(Debug)]
39pub struct Cfg {
40    tab_len: usize,
41    tab_level: u8,
42    columns: usize,
43}
44
45impl Default for Cfg {
46
47    fn default() -> Self {
48        Self::new(4, 0, 128)
49    }
50
51}
52
53impl Cfg {
54
55    /// # Makes new instance
56    pub const fn new(tab_len: usize, tab_level: u8, columns: usize) -> Self {
57        Self {
58            tab_len,
59            tab_level,
60            columns,
61        }
62    }
63
64    /// # Length of a tab
65    pub fn tab_len(&self) -> usize {
66        self.tab_len
67    }
68
69    /// # Tab level
70    pub fn tab_level(&self) -> u8 {
71        self.tab_level
72    }
73
74    /// # Increments level
75    ///
76    /// This function uses `saturating_add()` while incrementing level.
77    pub fn increment_level(&self) -> Self {
78        Self::new(self.tab_len, self.tab_level.saturating_add(1), self.columns)
79    }
80
81    /// # Columns
82    pub fn columns(&self) -> usize {
83        self.columns
84    }
85
86}