1 //! Configuration options related to rewriting a list.
3 use rustfmt_config_proc_macro::config_type;
5 use crate::config::IndentStyle;
7 /// The definitive formatting tactic for lists.
8 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
9 pub enum DefinitiveListTactic {
13 /// Special case tactic for `format!()`, `write!()` style macros.
17 impl DefinitiveListTactic {
18 pub fn ends_with_newline(&self, indent_style: IndentStyle) -> bool {
20 IndentStyle::Block => *self != DefinitiveListTactic::Horizontal,
21 IndentStyle::Visual => false,
26 /// Formatting tactic for lists. This will be cast down to a
27 /// `DefinitiveListTactic` depending on the number and length of the items and
33 /// All items on one row.
35 /// Try Horizontal layout, if that fails then vertical.
37 /// HorizontalVertical with a soft limit of n characters.
38 LimitedHorizontalVertical(usize),
39 /// Pack as many items as possible per row over (possibly) many rows.
44 pub enum SeparatorTactic {
50 impl SeparatorTactic {
51 pub fn from_bool(b: bool) -> SeparatorTactic {
53 SeparatorTactic::Always
55 SeparatorTactic::Never
60 /// Where to put separator.
62 pub enum SeparatorPlace {
68 pub fn is_front(self) -> bool {
69 self == SeparatorPlace::Front
72 pub fn is_back(self) -> bool {
73 self == SeparatorPlace::Back
77 default: SeparatorPlace,
78 tactic: DefinitiveListTactic,
82 DefinitiveListTactic::Vertical => default,