1 //! Configuration options related to rewriting a list.
3 use crate::config::config_type::ConfigType;
4 use crate::config::IndentStyle;
6 /// The definitive formatting tactic for lists.
7 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
8 pub enum DefinitiveListTactic {
12 /// Special case tactic for `format!()`, `write!()` style macros.
16 impl DefinitiveListTactic {
17 pub fn ends_with_newline(&self, indent_style: IndentStyle) -> bool {
19 IndentStyle::Block => *self != DefinitiveListTactic::Horizontal,
20 IndentStyle::Visual => false,
25 /// Formatting tactic for lists. This will be cast down to a
26 /// `DefinitiveListTactic` depending on the number and length of the items and
28 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
32 // All items on one row.
34 // Try Horizontal layout, if that fails then vertical.
36 // HorizontalVertical with a soft limit of n characters.
37 LimitedHorizontalVertical(usize),
38 // Pack as many items as possible per row over (possibly) many rows.
42 impl_enum_serialize_and_deserialize!(ListTactic, Vertical, Horizontal, HorizontalVertical, Mixed);
44 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
45 pub enum SeparatorTactic {
51 impl_enum_serialize_and_deserialize!(SeparatorTactic, Always, Never, Vertical);
53 impl SeparatorTactic {
54 pub fn from_bool(b: bool) -> SeparatorTactic {
56 SeparatorTactic::Always
58 SeparatorTactic::Never
63 /// Where to put separator.
64 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
65 pub enum SeparatorPlace {
70 impl_enum_serialize_and_deserialize!(SeparatorPlace, Front, Back);
73 pub fn is_front(self) -> bool {
74 self == SeparatorPlace::Front
77 pub fn is_back(self) -> bool {
78 self == SeparatorPlace::Back
82 default: SeparatorPlace,
83 tactic: DefinitiveListTactic,
87 DefinitiveListTactic::Vertical => default,