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 /// Tactic for nested import.
24 /// Special case tactic for `format!()`, `write!()` style macros.
28 impl DefinitiveListTactic {
29 pub fn ends_with_newline(&self, indent_style: IndentStyle) -> bool {
31 IndentStyle::Block => *self != DefinitiveListTactic::Horizontal,
32 IndentStyle::Visual => false,
37 /// Formatting tactic for lists. This will be cast down to a
38 /// `DefinitiveListTactic` depending on the number and length of the items and
40 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
44 // All items on one row.
46 // Try Horizontal layout, if that fails then vertical.
48 // HorizontalVertical with a soft limit of n characters.
49 LimitedHorizontalVertical(usize),
50 // Pack as many items as possible per row over (possibly) many rows.
54 impl_enum_serialize_and_deserialize!(ListTactic, Vertical, Horizontal, HorizontalVertical, Mixed);
56 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
57 pub enum SeparatorTactic {
63 impl_enum_serialize_and_deserialize!(SeparatorTactic, Always, Never, Vertical);
65 impl SeparatorTactic {
66 pub fn from_bool(b: bool) -> SeparatorTactic {
68 SeparatorTactic::Always
70 SeparatorTactic::Never
75 /// Where to put separator.
76 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
77 pub enum SeparatorPlace {
82 impl_enum_serialize_and_deserialize!(SeparatorPlace, Front, Back);
85 pub fn is_front(&self) -> bool {
86 *self == SeparatorPlace::Front
89 pub fn is_back(&self) -> bool {
90 *self == SeparatorPlace::Back
94 default: SeparatorPlace,
95 tactic: DefinitiveListTactic,
99 DefinitiveListTactic::Vertical => default,