Jump to content

Rust: Difference between revisions

From Bath Wiki
Update and add sections on useful tools.
m Pm2022 moved page BOSS/Languages/Rust to Rust
 
(One intermediate revision by the same user not shown)
Line 33: Line 33:


You can then use <code>cargo machete</code> to remove unused dependencies.
You can then use <code>cargo machete</code> to remove unused dependencies.
[[Category:Bath Open Source Society]]
[[Category:Programming language guidelines]]

Latest revision as of 07:03, 26 August 2026

The Rust compiler is pretty pedantic by default, however, we have a few recommendations:

  • Change the default check command in VSCode (instead of check use clippy).
  • 4 spaces for tabs.
  • Macros are cool but don’t overuse them.
  • Use rustfmt: cargo fmt.

Recommended tools

Bacon

Get bacon, open it in another terminal window, leave it running while you edit. It will save you recompiling constantly to get the verbose compiler output.

It also has handy features:

  • a - to check all.
  • c - to clippy all.
  • t - to run tests.
  • n - to run tests via cargo-nextest.

You can also make it run pedantic checks with bacon pedantic.

Audit

cargo install cargo-audit (or use cargo-binstall).

You can then run cargo audit to audit your dependencies for security vulnerabilities.

Flamegraph

cargo install cargo-flamegraph (or use cargo-binstall).

You can then use CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph [-- args-for-your-project] to generate a Flamegraph for profiling and optimising your project.

Machete

cargo install cargo-machete (or use cargo-binstall).

You can then use cargo machete to remove unused dependencies.