1#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[cfg_attr(feature = "serde", serde(default))]
5pub struct Config {
6 pub tab_spaces: usize,
8 pub max_width: usize,
10 pub blank_lines_upper_bound: usize,
12 pub collapse_markup_spaces: bool,
14 pub reorder_import_items: bool,
16 pub wrap_text: bool,
19}
20
21impl Default for Config {
22 fn default() -> Self {
23 Self {
24 tab_spaces: 2,
25 max_width: 80,
26 blank_lines_upper_bound: 2,
27 reorder_import_items: true,
28 collapse_markup_spaces: false,
29 wrap_text: false,
30 }
31 }
32}
33
34impl Config {
35 pub fn new() -> Self {
36 Default::default()
37 }
38
39 pub fn with_width(mut self, max_width: usize) -> Self {
40 self.max_width = max_width;
41 self
42 }
43
44 pub fn with_tab_spaces(mut self, tab_spaces: usize) -> Self {
45 self.tab_spaces = tab_spaces;
46 self
47 }
48
49 pub fn chain_width(&self) -> usize {
50 const CHAIN_WIDTH_RATIO: f32 = 0.6;
51 (self.max_width as f32 * CHAIN_WIDTH_RATIO) as usize
52 }
53
54 pub fn with_wrap_text(mut self, wrap_text: bool) -> Self {
55 self.wrap_text = wrap_text;
56 self
57 }
58}