Rust: Difference between revisions
Translate from boss.bathcs.com |
m Pm2022 moved page BOSS/Languages/Rust to Rust |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
The | 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 <code>clippy</code>) | * Change the default check command in VSCode (instead of check use <code>clippy</code>). | ||
* 4 spaces for tabs | * 4 spaces for tabs. | ||
* Macros are cool but don’t overuse them. | * Macros are cool but don’t overuse them. | ||
* Use rustfmt: <code>cargo fmt</code>. | |||
== | = Recommended tools = | ||
== Bacon == | |||
Get [https://github.com/Canop/bacon 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: | |||
* <code>a</code> - to check all. | |||
* <code>c</code> - to clippy all. | |||
* <code>t</code> - to run tests. | |||
* <code>n</code> - to run tests via [https://nexte.st/ <code>cargo-nextest</code>]. | |||
You can also make it run pedantic checks with <code>bacon pedantic</code>. | |||
== Audit == | |||
<code>cargo install cargo-audit</code> (or use [https://github.com/cargo-bins/cargo-binstall <code>cargo-binstall</code>]). | |||
You can then run <code>cargo audit</code> to audit your dependencies for security vulnerabilities. | |||
== Flamegraph == | |||
<code>cargo install cargo-flamegraph</code> (or use [https://github.com/cargo-bins/cargo-binstall <code>cargo-binstall</code>]). | |||
You can then use <code>CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph [-- args-for-your-project]</code> to generate a [https://www.brendangregg.com/flamegraphs.html Flamegraph] for profiling and optimising your project. | |||
== Machete == | |||
<code>cargo install cargo-machete</code> (or use [https://github.com/cargo-bins/cargo-binstall <code>cargo-binstall</code>]). | |||
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 viacargo-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.