Skip to content

Commit

Permalink
doc: add style guide (#660)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Matuszewski <[email protected]>
  • Loading branch information
Wodann and Xanewok authored Sep 12, 2024
1 parent a0601cb commit 7080c8d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
59 changes: 59 additions & 0 deletions book/src/02_development/06_style_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Style Guide

This is a style guide for the EDR project.

## Procedural derive macros

When deriving multiple traits, use the following rules to order them:

1. Standard library traits before external crates
2. Sub-traits before super-traits
3. Alphabetical order

For example:

```rust
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
```

Or, for sub- and super-traits:

```rust
#[derive(PartialEq, Eq, PartialOrd, Ord)]
```

## Member ordering

When adding a variant to an `enum` or a field to a `struct` or enum variant, by default follow alphabetical order. If it makes more sense to follow custom ordering, feel free to do so.

### Member functions

For member functions, use the following default rules to order them:

1. Public members before private members
2. Alphabetical order

Again, if it makes more sense to follow custom ordering, feel free to do so.

### Example

```rust
struct Foo {
bar: u32,
baz: u32,
}

impl Foo {
pub fn bar_mut(&mut self) -> &mut u32 {
&mut self.bar
}

pub fn baz(&self) -> u32 {
self.baz
}

fn bar(&self) -> u32 {
self.bar
}
}
```
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Local release](02_development/03_local_release.md)
- [Update N-API targets](02_development/04_update_napi_targets.md)
- [Using pnpm link](02_development/05_pnpm_link.md)
- [Style Guide](02_development/06_style_guide.md)

- [Release](./03_release.md)

Expand Down

0 comments on commit 7080c8d

Please sign in to comment.