Rust Demo for the Learning session
Install the Rust using the Rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Update the rust version(s):
rustup update
For more information (for example install the nightly
version of rust),
take a look here.
Cargo is the Rust package manager. Cargo downloads your Rust package's dependencies, compiles your packages, makes distributable packages, and uploads them to crates.io, the Rust community’s package registry. You can contribute to this book on GitHub.
# --bin is default (you will be creating an executable binary)
cargo new --bin my-ultimate-app
# --lib is for libraries
cargo new --lib my-ultimate-lib
Run the tests:
cargo test
Run the main.rs
(for binary only):
cargo run
Add a dependency to your project - there are 2 options, you can either manually edit: Cargo.toml
or run cargo add
Edit the Cargo.toml
file:
[dependencies]
serde = { version = "1.0.152", features = ["derive"] }
Run the cargo add
:
cargo add serde
# or with features
cargo add serde --features derive
Install the rust-analyzer
:
- Extension for the VSCode
- Manual installation instructions
To use Clippy, you need to install it using the Rustup:
rustup component add clippy
Then you can run it:
cargo clippy
# or with fix
cargo clippy --fix
For other tools and components take a look:
- Rustup Components (example:
rustfmt
)
- Rust Book
- []