1#[derive(Debug, Clone, Copy)]
2pub struct FormatterConfig {
3 put_fn_params_on_new_lines: bool,
4 use_set_notation_for_types: bool,
5 join_comments: bool,
6 newlines_between_items: usize,
7 newlines_between_comment_and_item: usize,
8 put_variants_on_new_lines: bool,
9 put_list_elements_on_new_lines: bool,
10 put_fn_body_on_new_line: bool,
11 tab_size: usize,
12 max_line_length: usize,
13 put_fn_args_on_new_lines: bool,
14 put_trailing_semis_on_let_bindings: bool,
15 backup: bool,
16}
17
18impl FormatterConfig {
19 pub fn newlines_between_items(&self) -> usize {
20 self.newlines_between_items
21 }
22
23 pub fn put_fn_params_on_new_lines(&self) -> bool {
24 self.put_fn_params_on_new_lines
25 }
26
27 pub fn use_set_notation_for_types(&self) -> bool {
28 self.use_set_notation_for_types
29 }
30
31 pub fn join_comments(&self) -> bool {
32 self.join_comments
33 }
34
35 pub fn newlines_between_comment_and_item(&self) -> usize {
36 self.newlines_between_comment_and_item
37 }
38
39 pub fn put_variants_on_new_lines(&self) -> bool {
40 self.put_variants_on_new_lines
41 }
42
43 pub fn put_list_elements_on_new_lines(&self) -> bool {
44 self.put_list_elements_on_new_lines
45 }
46
47 pub fn put_fn_body_on_new_line(&self) -> bool {
48 self.put_fn_body_on_new_line
49 }
50
51 pub fn tab_size(&self) -> usize {
52 self.tab_size
53 }
54
55 pub fn max_line_length(&self) -> usize {
56 self.max_line_length
57 }
58
59 pub fn put_fn_args_on_new_lines(&self) -> bool {
60 self.put_fn_args_on_new_lines
61 }
62
63 pub fn put_trailing_semis_on_let_bindings(&self) -> bool {
64 self.put_trailing_semis_on_let_bindings
65 }
66
67 pub fn backup(&self) -> bool {
68 self.backup
69 }
70
71 pub(crate) fn as_builder(&self) -> FormatterConfigBuilder {
72 FormatterConfigBuilder {
73 put_fn_params_on_new_lines: self.put_fn_params_on_new_lines,
74 use_set_notation_for_types: self.use_set_notation_for_types,
75 join_comments: self.join_comments,
76 newlines_between_items: self.newlines_between_items,
77 newlines_between_comment_and_item: self.newlines_between_comment_and_item,
78 put_variants_on_new_lines: self.put_variants_on_new_lines,
79 put_list_elements_on_new_lines: self.put_list_elements_on_new_lines,
80 put_fn_body_on_new_line: self.put_fn_body_on_new_line,
81 tab_size: self.tab_size,
82 max_line_length: self.max_line_length,
83 put_fn_args_on_new_lines: self.put_fn_args_on_new_lines,
84 put_trailing_semis_on_let_bindings: self.put_trailing_semis_on_let_bindings,
85 backup: self.backup,
86 }
87 }
88}
89
90impl Default for FormatterConfig {
91 fn default() -> Self {
92 FormatterConfigBuilder::default().build()
93 }
94}
95
96pub struct FormatterConfigBuilder {
97 put_fn_params_on_new_lines: bool,
98 use_set_notation_for_types: bool,
99 join_comments: bool,
100 newlines_between_items: usize,
101 newlines_between_comment_and_item: usize,
102 put_variants_on_new_lines: bool,
103 put_list_elements_on_new_lines: bool,
104 put_fn_body_on_new_line: bool,
105 tab_size: usize,
106 max_line_length: usize,
107 put_fn_args_on_new_lines: bool,
108 put_trailing_semis_on_let_bindings: bool,
109 backup: bool,
110}
111
112impl FormatterConfigBuilder {
113 pub fn put_fn_params_on_new_lines(
114 self,
115 put_fn_params_on_new_lines: bool,
116 ) -> Self {
117 Self {
118 put_fn_params_on_new_lines,
119 ..self
120 }
121 }
122
123 pub fn use_set_notation_for_types(
124 self,
125 use_set_notation_for_types: bool,
126 ) -> Self {
127 Self {
128 use_set_notation_for_types,
129 ..self
130 }
131 }
132
133 pub fn join_comments(
134 self,
135 join_comments: bool,
136 ) -> Self {
137 Self { join_comments, ..self }
138 }
139
140 pub fn newlines_between_items(
141 self,
142 newlines_between_items: usize,
143 ) -> Self {
144 Self {
145 newlines_between_items,
146 ..self
147 }
148 }
149
150 pub fn newlines_between_comment_and_item(
151 self,
152 newlines_between_comment_and_item: usize,
153 ) -> Self {
154 Self {
155 newlines_between_comment_and_item,
156 ..self
157 }
158 }
159
160 pub fn put_variants_on_new_lines(
161 self,
162 put_variants_on_new_lines: bool,
163 ) -> Self {
164 Self {
165 put_variants_on_new_lines,
166 ..self
167 }
168 }
169
170 pub fn put_list_elements_on_new_lines(
171 self,
172 put_list_elements_on_new_lines: bool,
173 ) -> Self {
174 Self {
175 put_list_elements_on_new_lines,
176 ..self
177 }
178 }
179
180 pub fn put_fn_body_on_new_line(
181 self,
182 put_fn_body_on_new_line: bool,
183 ) -> Self {
184 Self {
185 put_fn_body_on_new_line,
186 ..self
187 }
188 }
189
190 pub fn tab_size(
191 self,
192 tab_size: usize,
193 ) -> Self {
194 Self { tab_size, ..self }
195 }
196
197 pub fn max_line_length(
198 self,
199 max_line_length: usize,
200 ) -> Self {
201 Self { max_line_length, ..self }
202 }
203
204 pub fn put_fn_args_on_new_lines(
205 self,
206 put_fn_args_on_new_lines: bool,
207 ) -> Self {
208 Self {
209 put_fn_args_on_new_lines,
210 ..self
211 }
212 }
213
214 pub fn put_trailing_semis_on_let_bindings(
215 self,
216 put_trailing_semis_on_let_bindings: bool,
217 ) -> Self {
218 Self {
219 put_trailing_semis_on_let_bindings,
220 ..self
221 }
222 }
223
224 pub fn backup(
225 self,
226 backup: bool,
227 ) -> Self {
228 Self { backup, ..self }
229 }
230
231 pub fn build(self) -> FormatterConfig {
232 FormatterConfig {
233 put_fn_params_on_new_lines: self.put_fn_params_on_new_lines,
234 use_set_notation_for_types: self.use_set_notation_for_types,
235 join_comments: self.join_comments,
236 newlines_between_items: self.newlines_between_items,
237 newlines_between_comment_and_item: self.newlines_between_comment_and_item,
238 put_variants_on_new_lines: self.put_variants_on_new_lines,
239 put_list_elements_on_new_lines: self.put_list_elements_on_new_lines,
240 put_fn_body_on_new_line: self.put_fn_body_on_new_line,
241 tab_size: self.tab_size,
242 max_line_length: self.max_line_length,
243 put_fn_args_on_new_lines: self.put_fn_args_on_new_lines,
244 put_trailing_semis_on_let_bindings: self.put_trailing_semis_on_let_bindings,
245 backup: self.backup,
246 }
247 }
248}
249
250impl Default for FormatterConfigBuilder {
251 fn default() -> Self {
252 Self {
253 put_fn_params_on_new_lines: true,
254 use_set_notation_for_types: true,
255 join_comments: true,
256 newlines_between_items: 1,
257 newlines_between_comment_and_item: 0,
258 put_variants_on_new_lines: true,
259 put_list_elements_on_new_lines: false,
260 put_fn_body_on_new_line: true,
261 tab_size: 2,
262 max_line_length: 80,
263 put_fn_args_on_new_lines: false,
264 put_trailing_semis_on_let_bindings: false,
265 backup: false,
266 }
267 }
268}