1#[derive(Debug, Clone, PartialEq)]
2pub struct TomlConfig {
3 pub enum_style: Option<EnumStyle>,
4 pub block_comment: bool,
5}
6
7impl Default for TomlConfig {
8 fn default() -> Self {
9 TomlConfig {
10 enum_style: None,
11 block_comment: true,
12 }
13 }
14}
15
16impl TomlConfig {
17 pub fn merge_parent(&mut self, parent: &TomlConfig) {
18 if self.enum_style.is_none() {
19 self.enum_style = parent.enum_style;
20 }
21 }
22}
23
24#[derive(Debug, Clone, Copy, PartialEq)]
25pub enum EnumStyle {
26 Single,
27 Expand,
28 Fold,
29 Flex(usize),
30}
31
32impl Default for EnumStyle {
33 fn default() -> Self {
34 EnumStyle::Flex(4)
35 }
36}
37
38impl EnumStyle {
39 pub fn can_expand(&self, variants_len: usize) -> bool {
40 use EnumStyle::*;
41 match self {
42 Expand => true,
43 Flex(limit) => variants_len <= *limit,
44 _ => false,
45 }
46 }
47
48 pub fn can_fold(&self, variants_len: usize) -> bool {
49 use EnumStyle::*;
50 match self {
51 Fold => true,
52 Flex(limit) => variants_len > *limit,
53 _ => false,
54 }
55 }
56}