-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Igor Matuszewski <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters