Skip to content

Commit 247c002

Browse files
committed
Define *small*
Closes #47
1 parent e075fc4 commit 247c002

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

guide/guide.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ typically by using a formatting tool's default settings.
2222

2323
## Formatting conventions
2424

25-
These formatting conventions are a work in progress, and may do anything they
26-
like, up to and including eating your laundry.
27-
28-
2925
### Indentation and line width
3026

3127
Use spaces, not tabs. Each level of indentation must be four spaces. The maximum
@@ -157,6 +153,35 @@ combining multiple `derive` attributes into a single attribute, the ordering of
157153
the derived names should be preserved. E.g., `#[derive(bar)] #[derive(foo)]
158154
struct Baz;` should be formatted to `#[derive(bar, foo)] struct Baz;`.
159155

156+
### *small* items
157+
158+
In many places in this guide we specify that a formatter may format an item
159+
differently if it is *small*, for example struct literals:
160+
161+
```rust
162+
// Normal formatting
163+
Foo {
164+
f1: an_expression,
165+
f2: another_expression(),
166+
}
167+
168+
// *small* formatting
169+
Foo { f1, f2 }
170+
```
171+
172+
We leave it to individual tools to decide on exactly what *small* means. In
173+
particular, tools are free to use different definitions in different
174+
circumstances.
175+
176+
Some suitable heuristics are the size of the item (in characters) or the
177+
complexity of an item (for example, that all components must be simple names,
178+
not more complex sub-expressions). For more discussion on suitable heuristics,
179+
see the discussion on [this issue](https://github.com/rust-lang-nursery/fmt-rfcs/issues/47).
180+
181+
Tools should give the user an option to ignore such heuristics and always use
182+
the normal formatting.
183+
184+
160185
## [Non-formatting conventions](advice.md)
161186

162187
## [Cargo.toml conventions](cargo.md)

0 commit comments

Comments
 (0)