This is an old revision of the document!
Rust cheatlist
Cargo
cargo new project_name
: Initializes a new Rust project named project_name in the current directory.cargo build
: Build program without optimizations. Output is stored in ./target/debug.cargo build –release
: Build program with runtime optimizations. Output is stored in ./target/release.
Variables
let foo = bar;
: Creates immutable variablefoo
and assigns it valuebar
.let mut foo = bar;
: Creates mutable varibalefoo
and assigns it valuebar
.
Terminology
- Associated function: functione implemented on a type rather than on a particular instance of the type. Similar as a static method in Java.
- Macro:
- Prelude:
- Trait:
Syntax
&var
: Passesvar
as a reference. Allows a function to access a variable without the need to copy it to the function's stack.&mut var
: Passesvar
as a mutable reference. Allows a function to access and alter the variable's value.