Skip to content

Commit cde4782

Browse files
committed
Ranges
Closes #60 cc #89
1 parent 6c702c4 commit cde4782

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

guide/expressions.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## Expressions
2+
13
### Closures
24

35
Don't put any extra spaces before the first `|` (unless the closure is prefixed
@@ -78,10 +80,27 @@ Do not put any spaces around the `.`.
7880
x.foo().bar().baz(x, y, z);
7981
```
8082

81-
### as
83+
### Casts (`as`)
8284

8385
Put spaces before and after `as`:
8486

8587
```rust
8688
let cstr = "Hi\0" as *const str as *const [u8] as *const std::os::raw::c_char;
87-
```
89+
```
90+
91+
92+
### Ranges
93+
94+
Do not put spaces in ranges, e.g., `0..10`, `x...y`, `..x.len()`, `foo..`.
95+
96+
When writing a range with both upper and lower bounds, if the line must be
97+
broken, break after the range operator and block indent the second expression:
98+
99+
```
100+
a_long_expression..
101+
another_long_expression
102+
```
103+
104+
For the sake of indicating precedence, we recommend that if either bound is a
105+
compound expression, then use parentheses around it, e.g., `..(x + 1)`,
106+
`(x.f)..(x.f.len())`, or `0..(x - 10)`.

0 commit comments

Comments
 (0)