Просмотр исходного кода

chore: update CODE_STYLE

Co-authored-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
thesimplekid 11 месяцев назад
Родитель
Сommit
4c2cb78327
1 измененных файлов с 53 добавлено и 4 удалено
  1. 53 4
      CODE_STYLE.md

+ 53 - 4
CODE_STYLE.md

@@ -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;
+```