aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-10-16 11:50:09 +0100
committerAleksey Kladov <[email protected]>2020-10-16 11:50:09 +0100
commit0c67edc0f7ebb7e6a265d4a925bc368e460cd8cb (patch)
treec0bec28be51fb28d6e92069388b2434e32c076b1
parent1de202010948c94658235f7cfe9b25dda0c7ddf3 (diff)
Expand code order section
-rw-r--r--docs/dev/style.md61
1 files changed, 50 insertions, 11 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md
index 883a6845d..7a64a0d22 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -366,27 +366,66 @@ People read things from top to bottom, so place most important things first.
366 366
367Specifically, if all items except one are private, always put the non-private item on top. 367Specifically, if all items except one are private, always put the non-private item on top.
368 368
369Put `struct`s and `enum`s first, functions and impls last.
370
371Do
372
373```rust 369```rust
374// Good 370// Good
375struct Foo { 371pub(crate) fn frobnicate() {
376 bars: Vec<Bar> 372 Helper::act()
373}
374
375#[derive(Default)]
376struct Helper { stuff: i32 }
377
378impl Helper {
379 fn act(&self) {
380
381 }
382}
383
384// Not as good
385#[derive(Default)]
386struct Helper { stuff: i32 }
387
388pub(crate) fn frobnicate() {
389 Helper::act()
377} 390}
378 391
379struct Bar; 392impl Helper {
393 fn act(&self) {
394
395 }
396}
380``` 397```
381 398
382rather than 399If there's a mixture of private and public items, put public items first.
400If function bodies are folded in the editor, the source code should read as documentation for the public API.
401
402Put `struct`s and `enum`s first, functions and impls last. Order types declarations in top-down manner.
383 403
384```rust 404```rust
405// Good
406struct Parent {
407 children: Vec<Child>
408}
409
410struct Child;
411
412impl Parent {
413}
414
415impl Child {
416}
417
385// Not as good 418// Not as good
386struct Bar; 419struct Child;
387 420
388struct Foo { 421impl Child {
389 bars: Vec<Bar> 422}
423
424struct Parent {
425 children: Vec<Child>
426}
427
428impl Parent {
390} 429}
391``` 430```
392 431