Skip to content

Commit 3b7c081

Browse files
committed
guide: type aliases
closes #32 cc #89
1 parent 35bff4c commit 3b7c081

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

guide/items.md

+27
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,33 @@ where
257257
}
258258
```
259259

260+
261+
### Type aliases
262+
263+
Type aliases should generally be kept on one line. If necessary to break the
264+
line, do so after the `=`; the right-hand-side should be block indented:
265+
266+
```rust
267+
pub type Foo = Bar<T>;
268+
269+
// If multi-line is required
270+
type VeryLongType<T, U: SomeBound> =
271+
AnEvenLongerType<T, U, Foo<T>>;
272+
```
273+
274+
Where possible avoid `where` clauses and keep type constraints inline. Where
275+
that is not possible split the line before and after the `where` clause (and
276+
split the `where` clause as normal), e.g.,
277+
278+
```rust
279+
type VeryLongType<T, U>
280+
where
281+
T: U::AnAssociatedType,
282+
U: SomeBound,
283+
= AnEvenLongerType<T, U, Foo<T>>;
284+
```
285+
286+
260287
### extern items
261288

262289
When writing extern items (such as `extern "C" fn`), always be explicit about

0 commit comments

Comments
 (0)