This project is a template containing Cargo workspace. Use it if you want to split your big project into several crates, 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 crate name to
workspace.membersin rootCargo.toml - If this crate is needed to be dependency of other crates
- Add following line to
workspace.dependenciesin rootCargo.toml[workspace.dependencies] example = { path = "example" }
- In dependent crate, add this to
dependencies[dependencies] example.workspace = true
- Add following line to
You should not add external dependency directly in crate'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 crate's Cargo.toml
[dependencies]
abc.workspace = true
# Or
abc = { workspace = true }To lint and format your whole project, use:
cargo clippy
cargo fmtQ: Why we use nightly toolchain?
A: Because some features, like disablingtrailing_commaonly available with nightly toolchain.
Note: it might require you to install nightly toolchain. In most cases, userustup toolchain install nightly
Settings > Rust > External Linters
- Enable
Run external linter on the fly - Select
Clippyas linter - Select
[default]underChannelselector
Settings > Rust > Rustfmt
- Select
[default]underChannelselector - Enable
Use Rustfmt instead of the built-in formatter - Click
Configure actions on saveand enable following:Reformat codeRearrange codeRun code cleanup