@@ -28,6 +28,22 @@ The proper ordering and spacing is:
28
28
29
29
Avoid comments within the signature itself.
30
30
31
+ If the function signature does not fit on one line, then break after the opening
32
+ parenthesis and before the closing parenthesis and put each argument on its own
33
+ block-indented line. For example,
34
+
35
+ ``` rust
36
+ fn foo (
37
+ arg1 : i32 ,
38
+ arg2 : i32 ,
39
+ ) -> i32 {
40
+ ...
41
+ }
42
+ ```
43
+
44
+ Note the trailing comma on the last argument.
45
+
46
+
31
47
### Tuples and tuple structs
32
48
33
49
Write the type list as you would a parameter list to a function.
@@ -117,6 +133,7 @@ union Foo {
117
133
}
118
134
```
119
135
136
+
120
137
### Tuple structs
121
138
122
139
Put the whole struct on one line if possible. Types in the parentheses should be
@@ -142,6 +159,45 @@ pub struct Foo(
142
159
```
143
160
144
161
162
+ ### Traits
163
+
164
+ Trait items should be block-indented. If there are no items, the trait may be
165
+ formatted on a single line. Otherwise there should be line-breaks after the
166
+ opening brace and before the closing brace:
167
+
168
+ ``` rust
169
+ trait Foo {}
170
+
171
+ pub trait Bar {
172
+ ...
173
+ }
174
+ ```
175
+
176
+ If the trait has bounds, there should be a space after the colon but not before
177
+ and before and after each ` + ` , e.g.,
178
+
179
+ ``` rust
180
+ trait Foo : Debug + Bar {}
181
+ ```
182
+
183
+ Prefer not to line-break in the bounds if possible (consider using a ` where `
184
+ clause). Prefer to break between bounds than to break any individual bound. If
185
+ you must break the bounds, put each bound (including the first) on its own
186
+ block-indented line, break before the ` + ` and put the opening brace on its own
187
+ line:
188
+
189
+ ``` rust
190
+ pub trait IndexRanges :
191
+ Index <Range <usize >, Output = Self >
192
+ + Index <RangeTo <usize >, Output = Self >
193
+ + Index <RangeFrom <usize >, Output = Self >
194
+ + Index <RangeFull , Output = Self >
195
+ {
196
+ ...
197
+ }
198
+ ```
199
+
200
+
145
201
### Extern crate
146
202
147
203
` extern crate foo; `
@@ -171,9 +227,35 @@ macro_rules! foo {
171
227
}
172
228
```
173
229
230
+
174
231
### Generics
175
232
176
- TODO
233
+ Prefer to put a generics clause on one line. Break other parts of an item
234
+ declaration rather than line-breaking a generics clause. If a generics clause is
235
+ large enough to require line-breaking, you should prefer to use a ` where ` clause
236
+ instead.
237
+
238
+ Do not put spaces before or after ` < ` nor before ` > ` . Only put a space after ` > `
239
+ if it is followed by a word or opening brace, not an opening parenthesis. There
240
+ should be a space after each comma and no trailing comma.
241
+
242
+ ``` rust
243
+ fn foo <T : Display , U : Debug >(x : Vec <T >, y : Vec <U >) ...
244
+
245
+ impl <T : Display , U : Debug > SomeType <T , U > { ...
246
+ ```
247
+
248
+ If the generics clause must be formatted across multiple lines, each parameter
249
+ should have its own block-indented line, there should be newlines after the
250
+ opening bracket and before the closing bracket, and the should be a trailing
251
+ comma.
252
+
253
+ ``` rust
254
+ fn foo <
255
+ T : Display ,
256
+ U : Debug ,
257
+ >(x : Vec <T >, y : Vec <U >) ...
258
+ ```
177
259
178
260
If an associated type is bound in a generic type , then there should be spaces on
179
261
either side of the `= `:
@@ -182,6 +264,8 @@ either side of the `=`:
182
264
<T : Example <Item = u32 >>
183
265
```
184
266
267
+ Prefer to use single - letter names for generic parameters .
268
+
185
269
186
270
### `where ` clauses
187
271
0 commit comments