Skip to content

Commit 1791495

Browse files
committed
guide: type aliases
closes #32 cc #89
1 parent 6c702c4 commit 1791495

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

guide/items.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,29 @@ Use `{}` for the full definition of the macro.
110110
macro_rules! foo {
111111
}
112112
```
113+
114+
115+
### Type aliases
116+
117+
Type aliases should generally be kept on one line. If necessary to break the
118+
line, do so after the `=`; the right-hand-side should be block indented:
119+
120+
```rust
121+
pub type Foo = Bar<T>;
122+
123+
// If multi-line is required
124+
type VeryLongType<T, U: SomeBound> =
125+
AnEvenLongerType<T, U, Foo<T>>;
126+
```
127+
128+
Where possible avoid `where` clauses and keep type constraints inline. Where
129+
that is not possible split the line before and after the `where` clause (and
130+
split the `where` clause as normal), e.g.,
131+
132+
```rust
133+
type VeryLongType<T, U>
134+
where
135+
T: U::AnAssociatedType,
136+
U: SomeBound,
137+
= AnEvenLongerType<T, U, Foo<T>>;
138+
```

0 commit comments

Comments
 (0)