chore: update CODE_STYLE

Co-authored-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
This commit is contained in:
thesimplekid
2024-04-10 13:53:53 +01:00
parent 973dc89b01
commit 4c2cb78327

View File

@@ -126,10 +126,7 @@ mod y;
// Finally, the internal crate modules and submodules
use crate::{};
use super::{};
// Re-exports are treated as item definitions rather than imports, so they go
// after imports and modules. Use them sparingly.
pub use crate::x::Z;
use self::y::Y;
```
## Import Style
@@ -150,6 +147,20 @@ impl core::fmt::Display for RenameError {
}
```
When imports sub-modules:
```rust
// GOOD
mod x;
use self::x::Y;
// BAD
mod x;
use x::Y;
```
## If-let
Avoid the `if let ... { } else { }` construct if possible, use `match` instead:
@@ -185,3 +196,41 @@ match this.as_ref() {
None => (),
}
```
## Sub-modules
Avoid the `mod x { .. }` construct if possible. Instead, crate a file `x.rs` and define it with `mod x;`
**This applies to all sub-modules except `tests` and `benches`.**
```rust
// GOOD
mod x;
// BAD
mod x {
..
}
```
```rust
// GOOD
#[cfg(test)]
mod tests {
..
}
// BAD
mod tests;
```
```rust
// GOOD
#[cfg(bench)]
mod benches {
..
}
// BAD
mod benches;
```