Rust (Cargo)
Tools
Rust projects use:
rustfmtfor formattingclippyfor checking code styles and issuescargofor compiling/package managementrustdocfor generating API documentation
Check and Fix
mono-dev provides wrapper for clippy with common clippy flags
Template: Taskfile.yml
version: '3'
includes:
cargo:
taskfile: mono-dev/task/cargo.yaml
internal: true
tasks:
check:
cmds:
- task: cargo:clippy-all
- task: cargo:fmt-check
fix:
cmds:
- task: cargo:fmt-fix
dev-doc:
cmds:
- task: cargo:watch-serve-doc
Clippy fix is not automated, because IMO sometimes the suggestions lead to worse code style and should be ignored.
For other clippy options, including feature flags and targets,
see the included Taskfile.
The dev-doc command uses shwoop and
to serve the documentation generated by cargo doc and watch for changes.
Using rustfmt
When running cargo fmt, it may not format all of the source files, especially if some
source files are conditionally compiled. In this case use the rustfmt-check and rustfmt-fix tasks
version: '3'
includes:
cargo:
taskfile: mono-dev/task/cargo.yaml
internal: true
tasks:
check:
cmds:
- task: cargo:clippy-all
- task: cargo:rustfmt-check
vars:
PATH: src
fix:
cmds:
- task: cargo:rustfmt-fix
vars:
PATH: src
Test
There’s no wrapper for test - just run cargo test