1#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub struct Config {
5 pub tab_spaces: usize,
7 pub max_width: usize,
9 pub blank_lines_upper_bound: usize,
11 pub reorder_import_items: bool,
14}
15
16impl Default for Config {
17 fn default() -> Self {
18 Self {
19 tab_spaces: 2,
20 max_width: 80,
21 blank_lines_upper_bound: 2,
22 reorder_import_items: false,
23 }
24 }
25}
26
27impl Config {
28 pub fn new() -> Self {
29 Default::default()
30 }
31
32 pub fn with_width(mut self, max_width: usize) -> Self {
33 self.max_width = max_width;
34 self
35 }
36
37 pub fn with_tab_spaces(mut self, tab_spaces: usize) -> Self {
38 self.tab_spaces = tab_spaces;
39 self
40 }
41
42 pub fn chain_width(&self) -> usize {
43 const CHAIN_WIDTH_RATIO: f32 = 0.6;
44 (self.max_width as f32 * CHAIN_WIDTH_RATIO) as usize
45 }
46}