|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -/// Formatting of chained expressions, i.e. expressions which are chained by |
12 |
| -/// dots: struct and enum field access, method calls, and try shorthand (?). |
13 |
| -/// |
14 |
| -/// Instead of walking these subexpressions one-by-one, as is our usual strategy |
15 |
| -/// for expression formatting, we collect maximal sequences of these expressions |
16 |
| -/// and handle them simultaneously. |
17 |
| -/// |
18 |
| -/// Whenever possible, the entire chain is put on a single line. If that fails, |
19 |
| -/// we put each subexpression on a separate, much like the (default) function |
20 |
| -/// argument function argument strategy. |
21 |
| -/// |
22 |
| -/// Depends on config options: `chain_indent` is the indent to use for |
23 |
| -/// blocks in the parent/root/base of the chain (and the rest of the chain's |
24 |
| -/// alignment). |
25 |
| -/// E.g., `let foo = { aaaa; bbb; ccc }.bar.baz();`, we would layout for the |
26 |
| -/// following values of `chain_indent`: |
27 |
| -/// Block: |
28 |
| -/// ``` |
29 |
| -/// let foo = { |
30 |
| -/// aaaa; |
31 |
| -/// bbb; |
32 |
| -/// ccc |
33 |
| -/// }.bar |
34 |
| -/// .baz(); |
35 |
| -/// ``` |
36 |
| -/// Visual: |
37 |
| -/// ``` |
38 |
| -/// let foo = { |
39 |
| -/// aaaa; |
40 |
| -/// bbb; |
41 |
| -/// ccc |
42 |
| -/// } |
43 |
| -/// .bar |
44 |
| -/// .baz(); |
45 |
| -/// ``` |
46 |
| -/// |
47 |
| -/// If the first item in the chain is a block expression, we align the dots with |
48 |
| -/// the braces. |
49 |
| -/// Block: |
50 |
| -/// ``` |
51 |
| -/// let a = foo.bar |
52 |
| -/// .baz() |
53 |
| -/// .qux |
54 |
| -/// ``` |
55 |
| -/// Visual: |
56 |
| -/// ``` |
57 |
| -/// let a = foo.bar |
58 |
| -/// .baz() |
59 |
| -/// .qux |
60 |
| -/// ``` |
| 11 | +//! Formatting of chained expressions, i.e. expressions which are chained by |
| 12 | +//! dots: struct and enum field access, method calls, and try shorthand (?). |
| 13 | +//! |
| 14 | +//! Instead of walking these subexpressions one-by-one, as is our usual strategy |
| 15 | +//! for expression formatting, we collect maximal sequences of these expressions |
| 16 | +//! and handle them simultaneously. |
| 17 | +//! |
| 18 | +//! Whenever possible, the entire chain is put on a single line. If that fails, |
| 19 | +//! we put each subexpression on a separate, much like the (default) function |
| 20 | +//! argument function argument strategy. |
| 21 | +//! |
| 22 | +//! Depends on config options: `chain_indent` is the indent to use for |
| 23 | +//! blocks in the parent/root/base of the chain (and the rest of the chain's |
| 24 | +//! alignment). |
| 25 | +//! E.g., `let foo = { aaaa; bbb; ccc }.bar.baz();`, we would layout for the |
| 26 | +//! following values of `chain_indent`: |
| 27 | +//! Block: |
| 28 | +//! ``` |
| 29 | +//! let foo = { |
| 30 | +//! aaaa; |
| 31 | +//! bbb; |
| 32 | +//! ccc |
| 33 | +//! }.bar |
| 34 | +//! .baz(); |
| 35 | +//! ``` |
| 36 | +//! Visual: |
| 37 | +//! ``` |
| 38 | +//! let foo = { |
| 39 | +//! aaaa; |
| 40 | +//! bbb; |
| 41 | +//! ccc |
| 42 | +//! } |
| 43 | +//! .bar |
| 44 | +//! .baz(); |
| 45 | +//! ``` |
| 46 | +//! |
| 47 | +//! If the first item in the chain is a block expression, we align the dots with |
| 48 | +//! the braces. |
| 49 | +//! Block: |
| 50 | +//! ``` |
| 51 | +//! let a = foo.bar |
| 52 | +//! .baz() |
| 53 | +//! .qux |
| 54 | +//! ``` |
| 55 | +//! Visual: |
| 56 | +//! ``` |
| 57 | +//! let a = foo.bar |
| 58 | +//! .baz() |
| 59 | +//! .qux |
| 60 | +//! ``` |
61 | 61 |
|
62 | 62 | use shape::Shape;
|
63 | 63 | use config::IndentStyle;
|
|
0 commit comments