1mod indent;
4mod max_line_length;
5mod newline;
6mod quotes;
7
8pub use indent::Indent;
9pub use max_line_length::MaxLineLength;
10pub use newline::NewlineStyle;
11pub use quotes::QuoteStyle;
12use schemars::JsonSchema;
13use toml_spanner::Toml;
14use toml_spanner::helper::display;
15use toml_spanner::helper::parse_string;
16
17fn sort_imports_default() -> bool {
19 true
20}
21
22fn sort_inputs_default() -> bool {
24 false
25}
26
27fn trailing_commas_default() -> bool {
29 true
30}
31
32fn reorder_sections_default() -> bool {
34 false
35}
36
37fn upgrade_deprecations_default() -> bool {
39 false
40}
41
42#[derive(Clone, Copy, Debug, PartialEq, Eq, Toml, JsonSchema)]
44#[toml(Toml, deny_unknown_fields)]
45pub struct Config {
46 #[toml(default)]
48 #[schemars(default)]
49 pub indent: Indent,
50 #[toml(default)]
52 #[schemars(default)]
53 pub max_line_length: MaxLineLength,
54 #[toml(default = sort_imports_default())]
56 #[schemars(default = "sort_imports_default")]
57 pub sort_imports: bool,
58 #[toml(default = sort_inputs_default())]
60 #[schemars(default = "sort_inputs_default")]
61 pub sort_inputs: bool,
62 #[toml(default = trailing_commas_default())]
64 #[schemars(default = "trailing_commas_default")]
65 pub trailing_commas: bool,
66 #[toml(default = reorder_sections_default())]
69 #[schemars(default = "reorder_sections_default")]
70 pub reorder_sections: bool,
71 #[toml(default = upgrade_deprecations_default())]
77 #[schemars(default = "upgrade_deprecations_default")]
78 pub upgrade_deprecations: bool,
79 #[toml(default, FromToml with = parse_string, ToToml with = display)]
81 #[schemars(default)]
82 pub newline_style: NewlineStyle,
83 #[toml(default, FromToml with = parse_string, ToToml with = display)]
85 #[schemars(default)]
86 pub quote_style: QuoteStyle,
87}
88
89impl Default for Config {
90 fn default() -> Self {
91 Self {
92 indent: Indent::default(),
93 max_line_length: MaxLineLength::default(),
94 sort_imports: sort_imports_default(),
95 sort_inputs: sort_inputs_default(),
96 trailing_commas: trailing_commas_default(),
97 reorder_sections: reorder_sections_default(),
98 upgrade_deprecations: upgrade_deprecations_default(),
99 newline_style: NewlineStyle::default(),
100 quote_style: QuoteStyle::default(),
101 }
102 }
103}
104
105impl Config {
106 pub fn indent(mut self, indent: Indent) -> Self {
108 self.indent = indent;
109 self
110 }
111
112 pub fn newline_style(mut self, newline_style: NewlineStyle) -> Self {
114 self.newline_style = newline_style;
115 self
116 }
117
118 pub fn quote_style(mut self, quote_style: QuoteStyle) -> Self {
120 self.quote_style = quote_style;
121 self
122 }
123
124 pub fn max_line_length(mut self, max_line_length: MaxLineLength) -> Self {
126 self.max_line_length = max_line_length;
127 self
128 }
129
130 pub fn sort_imports(mut self, sort_imports: bool) -> Self {
132 self.sort_imports = sort_imports;
133 self
134 }
135
136 pub fn sort_inputs(mut self, sort_inputs: bool) -> Self {
138 self.sort_inputs = sort_inputs;
139 self
140 }
141
142 pub fn trailing_commas(mut self, trailing_commas: bool) -> Self {
144 self.trailing_commas = trailing_commas;
145 self
146 }
147
148 pub fn reorder_sections(mut self, reorder_sections: bool) -> Self {
150 self.reorder_sections = reorder_sections;
151 self
152 }
153
154 pub fn upgrade_deprecations(mut self, upgrade_deprecations: bool) -> Self {
156 self.upgrade_deprecations = upgrade_deprecations;
157 self
158 }
159}