rustfmt_nightly/config/
lists.rs
1use rustfmt_config_proc_macro::config_type;
4
5use crate::config::IndentStyle;
6
7#[derive(Eq, PartialEq, Debug, Copy, Clone)]
9pub enum DefinitiveListTactic {
10 Vertical,
11 Horizontal,
12 Mixed,
13 SpecialMacro(usize),
15}
16
17impl DefinitiveListTactic {
18 pub fn ends_with_newline(&self, indent_style: IndentStyle) -> bool {
19 match indent_style {
20 IndentStyle::Block => *self != DefinitiveListTactic::Horizontal,
21 IndentStyle::Visual => false,
22 }
23 }
24}
25
26#[config_type]
30pub enum ListTactic {
31 Vertical,
33 Horizontal,
35 HorizontalVertical,
37 LimitedHorizontalVertical(usize),
39 Mixed,
41}
42
43#[config_type]
44pub enum SeparatorTactic {
45 Always,
46 Never,
47 Vertical,
48}
49
50impl SeparatorTactic {
51 pub fn from_bool(b: bool) -> SeparatorTactic {
52 if b {
53 SeparatorTactic::Always
54 } else {
55 SeparatorTactic::Never
56 }
57 }
58}
59
60#[config_type]
62pub enum SeparatorPlace {
63 Front,
64 Back,
65}
66
67impl SeparatorPlace {
68 pub fn is_front(self) -> bool {
69 self == SeparatorPlace::Front
70 }
71
72 pub fn is_back(self) -> bool {
73 self == SeparatorPlace::Back
74 }
75
76 pub fn from_tactic(
77 default: SeparatorPlace,
78 tactic: DefinitiveListTactic,
79 sep: &str,
80 ) -> SeparatorPlace {
81 match tactic {
82 DefinitiveListTactic::Vertical => default,
83 _ => {
84 if sep == "," {
85 SeparatorPlace::Back
86 } else {
87 default
88 }
89 }
90 }
91 }
92}