1mod indent;
4mod max_line_length;
5mod newline;
6
7pub use indent::Indent;
8pub use max_line_length::MaxLineLength;
9pub use newline::NewlineStyle;
10use schemars::JsonSchema;
11use toml_spanner::Toml;
12use toml_spanner::helper::display;
13use toml_spanner::helper::parse_string;
14
15fn sort_imports_default() -> bool {
17 true
18}
19
20fn sort_inputs_default() -> bool {
22 false
23}
24
25fn trailing_commas_default() -> bool {
27 true
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq, Toml, JsonSchema)]
32#[toml(Toml, deny_unknown_fields)]
33pub struct Config {
34 #[toml(default)]
36 #[schemars(default)]
37 pub indent: Indent,
38 #[toml(default)]
40 #[schemars(default)]
41 pub max_line_length: MaxLineLength,
42 #[toml(default = sort_imports_default())]
44 #[schemars(default = "sort_imports_default")]
45 pub sort_imports: bool,
46 #[toml(default = sort_inputs_default())]
48 #[schemars(default = "sort_inputs_default")]
49 pub sort_inputs: bool,
50 #[toml(default = trailing_commas_default())]
52 #[schemars(default = "trailing_commas_default")]
53 pub trailing_commas: bool,
54 #[toml(default, FromToml with = parse_string, ToToml with = display)]
56 #[schemars(default)]
57 pub newline_style: NewlineStyle,
58}
59
60impl Default for Config {
61 fn default() -> Self {
62 Self {
63 indent: Indent::default(),
64 max_line_length: MaxLineLength::default(),
65 sort_imports: sort_imports_default(),
66 sort_inputs: sort_inputs_default(),
67 trailing_commas: trailing_commas_default(),
68 newline_style: NewlineStyle::default(),
69 }
70 }
71}
72
73impl Config {
74 pub fn indent(mut self, indent: Indent) -> Self {
76 self.indent = indent;
77 self
78 }
79
80 pub fn newline_style(mut self, newline_style: NewlineStyle) -> Self {
82 self.newline_style = newline_style;
83 self
84 }
85
86 pub fn max_line_length(mut self, max_line_length: MaxLineLength) -> Self {
88 self.max_line_length = max_line_length;
89 self
90 }
91
92 pub fn sort_imports(mut self, sort_imports: bool) -> Self {
94 self.sort_imports = sort_imports;
95 self
96 }
97
98 pub fn sort_inputs(mut self, sort_inputs: bool) -> Self {
100 self.sort_inputs = sort_inputs;
101 self
102 }
103
104 pub fn trailing_commas(mut self, trailing_commas: bool) -> Self {
106 self.trailing_commas = trailing_commas;
107 self
108 }
109}