Rust
Things to know
- no variadic functions (unknown number of parameters), except for macros
println!(...)
. dbg!()
allows to debug an expression and also returns the result-
#![allow(unused)] fn main() { let a = dbg!(5+1)+8; println!("{a}"); }
-
Good practice
Build
By default, binaries are compiled in unwind
mode which raises the call stack. Using abort
allows to have smaller binaries but the Drop
is not done (memory not cleared).
[profile.release]
panic = 'abort'
Performing a panic
in a panic
is equivalent to an abort
, it is a bad practice.
Linters
- Clippy: A collection of lints to catch common mistakes and improve your Rust code.
- miri: An interpreter for Rust's mid-level intermediate representation.
- valgrind: detect many memory management and threading bugs, and profile your programs in detail.
- cargo-geiger: Detects usage of unsafe Rust in a Rust crate and its dependencies.