- Build:
cargo build --workspace - Lint:
cargo clippy --workspace --bins --examples --tests -- --no-deps - Test (all):
cargo testorcargo nextest run - Test (single):
cargo test test_nameorcargo nextest run test_name - Test (specific crate):
cargo test -p crate-name - Coverage:
cargo tarpaulin --engine llvm -o html
- Use 2-space indentation (no tabs)
- Max line width: 100 characters
- Error handling: Use
anyhowfor general errors,thiserrorfor custom error types - Use
#[cfg(test)]and separate test files with_test.rssuffix - Imports: Group imports with
Onestyle, module granularity, andHorizontalVerticallayout - Use workspace dependencies from Cargo.toml where available
- Edition: Rust 2024
- Make sure to run
cargo +nightly fmtafter making changes to apply default formatting rules. - Use pattern matching with if-let and match expressions for error handling
- When you write comments, flow them out to 100 columns for wrapping
- Avoid redundant documentation for the sake of convention. For example
- Don't include an Errors section if the only errors are generic failures.
- Don't include an Arguments section if the arguments are obvious based on the function signature.
- Test files should be placed adjacent to the implementation file they're testing
- Test files should be named with a
_test.rssuffix (e.g.,network_quality_test.rs) - Link test files in the implementation file using the following pattern at the top of the file, right below the license header and optional module-level docs.
#[cfg(test)] #[path = "./file_name_test.rs"] mod tests;
- Tests in the same file as the implementation code should be avoided
- Test names should not start with
test_, as this is redundant - Use module-level clippy allow blocks instead of per-test allows:
This should be placed at the top of the test file, after the license header and before imports.
#![allow(clippy::unwrap_used)]
- After generating or modifying code, always run clippy to check for static lint violations:
cargo clippy --workspace --bins --examples --tests -- --no-deps - For automatic fixing of some linting issues, use the
--fixflag:cargo clippy --workspace --bins --examples --tests --fix -- --no-deps - Fix any remaining warnings before committing code
- Running clippy is especially important after code generation or modification to catch any potential issues