Modules and Crates
Default to the narrowest visibility (narrow-visibility)
Start private,
then widen to pub(super), pub(crate), or pub
only when an actual external consumer requires it.
// Good — restricted to the parent module
pub(super) static I8042_CONTROLLER:
Once<SpinLock<I8042Controller, LocalIrqDisabled>> = Once::new();
pub(super) fn init() -> Result<(), I8042ControllerError> {
// ...
}
// Bad — unnecessarily wide
pub static I8042_CONTROLLER: ...
Use workspace dependencies (workspace-deps)
Always declare shared dependencies
in the workspace [workspace.dependencies] table
and reference them with .workspace = true
in member crates.
# In the workspace root Cargo.toml
[workspace.dependencies]
ostd = { version = "0.17.0", path = "ostd" }
bitflags = "2.6"
# In a member crate's Cargo.toml
[dependencies]
ostd.workspace = true
bitflags.workspace = true