1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Configuration options related to rewriting a list.
13 use config::config_type::ConfigType;
14 use config::IndentStyle;
16 /// The definitive formatting tactic for lists.
17 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
18 pub enum DefinitiveListTactic {
22 /// Special case tactic for `format!()`, `write!()` style macros.
26 impl DefinitiveListTactic {
27 pub fn ends_with_newline(&self, indent_style: IndentStyle) -> bool {
29 IndentStyle::Block => *self != DefinitiveListTactic::Horizontal,
30 IndentStyle::Visual => false,
35 /// Formatting tactic for lists. This will be cast down to a
36 /// `DefinitiveListTactic` depending on the number and length of the items and
38 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
42 // All items on one row.
44 // Try Horizontal layout, if that fails then vertical.
46 // HorizontalVertical with a soft limit of n characters.
47 LimitedHorizontalVertical(usize),
48 // Pack as many items as possible per row over (possibly) many rows.
52 impl_enum_serialize_and_deserialize!(ListTactic, Vertical, Horizontal, HorizontalVertical, Mixed);
54 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
55 pub enum SeparatorTactic {
61 impl_enum_serialize_and_deserialize!(SeparatorTactic, Always, Never, Vertical);
63 impl SeparatorTactic {
64 pub fn from_bool(b: bool) -> SeparatorTactic {
66 SeparatorTactic::Always
68 SeparatorTactic::Never
73 /// Where to put separator.
74 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
75 pub enum SeparatorPlace {
80 impl_enum_serialize_and_deserialize!(SeparatorPlace, Front, Back);
83 pub fn is_front(self) -> bool {
84 self == SeparatorPlace::Front
87 pub fn is_back(self) -> bool {
88 self == SeparatorPlace::Back
92 default: SeparatorPlace,
93 tactic: DefinitiveListTactic,
97 DefinitiveListTactic::Vertical => default,