1#[derive(Debug, Clone, PartialEq)]
2pub struct TomlConfig {
3 pub enum_style: Option<EnumStyle>,
4 pub option_style: Option<OptionStyle>,
5 pub commented: bool,
6 pub comment_style: Option<CommentStyle>,
7}
8
9impl Default for TomlConfig {
10 fn default() -> Self {
11 TomlConfig {
12 enum_style: None,
13 option_style: None,
14 commented: true,
15 comment_style: None,
16 }
17 }
18}
19
20impl TomlConfig {
21 pub fn merge_parent(&mut self, parent: &TomlConfig) {
22 if self.enum_style.is_none() {
23 self.enum_style = parent.enum_style;
24 }
25 if self.option_style.is_none() {
26 self.option_style = parent.option_style;
27 }
28 if self.comment_style.is_none() {
29 self.comment_style = parent.comment_style;
30 }
31 }
32
33 pub fn is_none_skipped(&self) -> bool {
34 if let Some(style) = self.option_style {
35 style.is_skip_none()
36 } else {
37 false
38 }
39 }
40
41 pub fn is_comment_hidden(&self) -> bool {
42 matches!(self.comment_style, Some(CommentStyle::Hide))
43 }
44}
45
46#[derive(Debug, Clone, Copy, PartialEq)]
47pub enum EnumStyle {
48 Single,
49 Expand,
50 Fold,
51 Flex(usize),
52}
53
54impl Default for EnumStyle {
55 fn default() -> Self {
56 EnumStyle::Flex(4)
57 }
58}
59
60impl EnumStyle {
61 pub fn can_expand(&self, variants_len: usize) -> bool {
62 use EnumStyle::*;
63 match self {
64 Expand => true,
65 Flex(limit) => variants_len <= *limit,
66 _ => false,
67 }
68 }
69
70 pub fn can_fold(&self, variants_len: usize) -> bool {
71 use EnumStyle::*;
72 match self {
73 Fold => true,
74 Flex(limit) => variants_len > *limit,
75 _ => false,
76 }
77 }
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Default)]
81pub enum OptionStyle {
82 SkipNone,
83 #[default]
84 ExpandNone,
85}
86
87impl OptionStyle {
88 pub fn is_skip_none(&self) -> bool {
89 matches!(self, OptionStyle::SkipNone)
90 }
91}
92
93#[derive(Debug, Clone, Copy, PartialEq, Default)]
94pub enum CommentStyle {
95 #[default]
96 Show,
97 Hide,
98}