This project is a template containing Cargo workspace. Use it if you want to split your big project into several subpackages, but share same settings and build it all together.
- Create folder containing
Cargo.tomland eithersrc/main.rsorsrc/lib.rs Cargo.tomlcontent:[package] name = "example" version.workspace = true description.workspace = true documentation.workspace = true homepage.workspace = true repository.workspace = true authors.workspace = true keywords.workspace = true categories.workspace = true edition.workspace = true rust-version.workspace = true [lints] workspace = true [dependencies]
- Add new subpackage name to
workspace.membersin rootCargo.toml - If this subpackage is needed to be dependency of other subpackages
- Add following line to
workspace.dependenciesin rootCargo.toml[workspace.dependencies] example = { path = "example" }
- In dependent subpackage, add this to
dependencies[dependencies] example.workspace = true
- Add following line to
You should not add external dependency directly in subpackage's Cargo.toml. Instead, add it in root Cargo.toml:
[workspace.dependencies]
abc = "1.2.3"
# Or
abc = { version = "1.2.3" }Then, add following line to subpackage's Cargo.toml
[dependencies]
abc.workspace = true
# Or
abc = { workspace = true }To lint and format your whole project, use:
cargo +nightly clippy
cargo +nightly fmtQ: Why we use
nightly?
A: Because some features, like disablingtrailing_commaonly available with nightly toolchain.
Note: it might require you to install nightly toolchain.
Settings > Rust > External Linters
- Enable
Run external linter on the fly - Select
Clippyas linter - Select
nightlyunderChannelselector
Settings > Rust > Rustfmt
- Select
nightlyunderChannelselector - Enable
Use Rustfmt instead of the built-in formatter - Click
Configure actions on saveand enable following:Reformat codeOptimize importsRearrange codeRun code cleanup