1mod indent;
4mod max_line_length;
5mod newline;
6
7pub use indent::Indent;
8pub use max_line_length::MaxLineLength;
9pub use newline::NewlineStyle;
10use toml_spanner::Toml;
11use toml_spanner::helper::display;
12use toml_spanner::helper::parse_string;
13
14const SORT_IMPORTS_DEFAULT: bool = true;
16const SORT_INPUTS_DEFAULT: bool = false;
18const TRAILING_COMMAS_DEFAULT: bool = true;
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Toml)]
23#[toml(Toml, deny_unknown_fields)]
24pub struct Config {
25 #[toml(default)]
27 pub indent: Indent,
28 #[toml(default)]
30 pub max_line_length: MaxLineLength,
31 #[toml(default = SORT_IMPORTS_DEFAULT)]
33 pub sort_imports: bool,
34 #[toml(default = SORT_INPUTS_DEFAULT)]
36 pub sort_inputs: bool,
37 #[toml(default = TRAILING_COMMAS_DEFAULT)]
39 pub trailing_commas: bool,
40 #[toml(default, FromToml with = parse_string, ToToml with = display)]
42 pub newline_style: NewlineStyle,
43}
44
45impl Default for Config {
46 fn default() -> Self {
47 Self {
48 indent: Indent::default(),
49 max_line_length: MaxLineLength::default(),
50 sort_imports: SORT_IMPORTS_DEFAULT,
51 sort_inputs: SORT_INPUTS_DEFAULT,
52 trailing_commas: TRAILING_COMMAS_DEFAULT,
53 newline_style: NewlineStyle::default(),
54 }
55 }
56}
57
58impl Config {
59 pub fn indent(mut self, indent: Indent) -> Self {
61 self.indent = indent;
62 self
63 }
64
65 pub fn newline_style(mut self, newline_style: NewlineStyle) -> Self {
67 self.newline_style = newline_style;
68 self
69 }
70
71 pub fn max_line_length(mut self, max_line_length: MaxLineLength) -> Self {
73 self.max_line_length = max_line_length;
74 self
75 }
76
77 pub fn sort_imports(mut self, sort_imports: bool) -> Self {
79 self.sort_imports = sort_imports;
80 self
81 }
82
83 pub fn sort_inputs(mut self, sort_inputs: bool) -> Self {
85 self.sort_inputs = sort_inputs;
86 self
87 }
88
89 pub fn trailing_commas(mut self, trailing_commas: bool) -> Self {
91 self.trailing_commas = trailing_commas;
92 self
93 }
94}