datex_core/fmt/
options.rs1#[derive(Clone, Debug, PartialEq, Eq)]
2pub struct FormattingOptions {
3 pub indent: usize,
5
6 pub max_width: usize,
8
9 pub trailing_comma: bool,
12
13 pub spaced_collections: bool,
16
17 pub space_in_collection: bool,
20
21 pub spaces_around_operators: bool,
24
25 pub type_declaration_formatting: TypeDeclarationFormatting,
28
29 pub statement_formatting: StatementFormatting,
31
32 pub variant_formatting: VariantFormatting,
34
35 pub bracket_style: BracketStyle,
37}
38
39#[derive(Clone, Debug, PartialEq, Eq)]
40pub enum BracketStyle {
41 KeepAll,
43
44 RemoveDuplicate,
46
47 Minimal,
49}
50
51#[derive(Clone, Debug, PartialEq, Eq)]
53pub enum VariantFormatting {
54 KeepAll,
56 WithSuffix,
58 WithoutSuffix,
60}
61
62#[derive(Clone, Debug, PartialEq, Eq)]
64pub enum StatementFormatting {
65 NewlineBetween,
67 SpaceBetween,
69 Compact,
71}
72
73#[derive(Clone, Debug, PartialEq, Eq)]
75pub enum TypeDeclarationFormatting {
76 Compact,
78 SpaceAroundColon,
80 SpaceAfterColon,
82}
83
84impl Default for FormattingOptions {
85 fn default() -> Self {
86 FormattingOptions {
87 indent: 4,
88 max_width: 40,
89 variant_formatting: VariantFormatting::KeepAll,
90 trailing_comma: true,
91 spaced_collections: false,
92 space_in_collection: true,
93 spaces_around_operators: true,
94 type_declaration_formatting:
95 TypeDeclarationFormatting::SpaceAfterColon,
96 statement_formatting: StatementFormatting::NewlineBetween,
97 bracket_style: BracketStyle::Minimal,
98 }
99 }
100}
101impl FormattingOptions {
102 pub fn compact() -> Self {
103 FormattingOptions {
104 indent: 2,
105 max_width: 40,
106 variant_formatting: VariantFormatting::WithoutSuffix,
107 trailing_comma: false,
108 spaced_collections: false,
109 space_in_collection: false,
110 spaces_around_operators: false,
111 type_declaration_formatting: TypeDeclarationFormatting::Compact,
112 statement_formatting: StatementFormatting::Compact,
113 bracket_style: BracketStyle::Minimal,
114 }
115 }
116}