1#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct FormatConfig {
6 pub max_width: usize,
9
10 pub indent_width: usize,
13
14 pub use_tabs: bool,
17
18 pub trailing_comma: TrailingComma,
21
22 pub newline: NewlineStyle,
25}
26
27impl Default for FormatConfig {
28 fn default() -> Self {
29 Self {
30 max_width: 100,
31 indent_width: 2,
32 use_tabs: false,
33 trailing_comma: TrailingComma::Always,
34 newline: NewlineStyle::Lf,
35 }
36 }
37}
38
39impl FormatConfig {
40 pub fn new() -> Self {
42 Self::default()
43 }
44
45 pub fn with_max_width(mut self, width: usize) -> Self {
47 self.max_width = width;
48 self
49 }
50
51 pub fn with_indent_width(mut self, width: usize) -> Self {
53 self.indent_width = width;
54 self
55 }
56
57 pub fn with_tabs(mut self, use_tabs: bool) -> Self {
59 self.use_tabs = use_tabs;
60 self
61 }
62
63 pub fn with_trailing_comma(mut self, policy: TrailingComma) -> Self {
65 self.trailing_comma = policy;
66 self
67 }
68
69 pub fn with_newline(mut self, style: NewlineStyle) -> Self {
71 self.newline = style;
72 self
73 }
74}
75
76#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
78pub enum TrailingComma {
79 #[default]
81 Always,
82 Never,
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
88pub enum NewlineStyle {
89 #[default]
91 Lf,
92 Crlf,
94}
95
96impl NewlineStyle {
97 pub fn as_str(self) -> &'static str {
99 match self {
100 NewlineStyle::Lf => "\n",
101 NewlineStyle::Crlf => "\r\n",
102 }
103 }
104}