Skip to content

Commit

Permalink
guide: type aliases
Browse files Browse the repository at this point in the history
closes #32
cc #89
  • Loading branch information
nrc committed Sep 14, 2017
1 parent 6c702c4 commit 1791495
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions guide/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,29 @@ Use `{}` for the full definition of the macro.
macro_rules! foo {
}
```


### Type aliases

Type aliases should generally be kept on one line. If necessary to break the
line, do so after the `=`; the right-hand-side should be block indented:

```rust
pub type Foo = Bar<T>;

// If multi-line is required
type VeryLongType<T, U: SomeBound> =
AnEvenLongerType<T, U, Foo<T>>;
```

Where possible avoid `where` clauses and keep type constraints inline. Where
that is not possible split the line before and after the `where` clause (and
split the `where` clause as normal), e.g.,

```rust
type VeryLongType<T, U>
where
T: U::AnAssociatedType,
U: SomeBound,
= AnEvenLongerType<T, U, Foo<T>>;
```

0 comments on commit 1791495

Please sign in to comment.