Notes on using the Rust Programming language
You can use the Rust Playground to try Rust without installing it.
- Website: https://www.rust-lang.org
- Install Rust: https://www.rust-lang.org/tools/install
- macOS or Linux:
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Windows
- Download and run the appropriate rustup installer for Windows (32 bit or 64 bit)
- macOS or Linux:
- Restart terminal window
- rustc --version
- cargo --version
- rustup update
- Install 'rust-analyzer' VS Code Extension
- Install 'CodeLLDB' VS Code Extension.
- Run 'cargo new <project_name>' from Terminal to create new Rust Project
- Run 'code <project_name>' from Terminal to open that project in VS Code
- Click on Run & Debug tab in VS Code
- Click on "Show all automatic debug configurations"
- Click on "Add configuration" in dropdown.
- Choose 'LLDB'
- Click 'Yes' on the dialog box that pops up.
- This will generate a new '.vscode/launch.json' file which will allow debugging.
- Set any breakpoints you need in the source.
- Go to the Run & Debug tab on VS Code.
- Click the Green arrow on the top to start running.
Command | Description |
---|---|
rustc file.rs | Compile the Rust code in the file 'file.rc' |
rustc --explain E0308 | Explain a Rust error message, such as E0308 in this example |
cargo run | Compile and run a debug version of the Rust project in the current folder |
cargo build | Build a debug version of the Rust project in the current folder. The executable will be in the file 'target/debug/PROJECT_NAME' |
cargo build --release | Build a release version of the Rust project in the current folder. The executable will be in the file 'target/release/PROJECT_NAME' |
cargo check | Checks to see if your Rust program will compile without generating an executable |
cargo new PROJECT_NAME | Create a new Rust project named PROJECT_NAME in a folder called PROJECT_NAME under the current folder |
File | Description |
---|---|
Cargo.toml | Project file containing configuration settings |
main.rs | Main file of the project. Execution starts here in the main() function. |
target/debug/PROJECT_NAME | Name of debug executable for the project named PROJECT_NAME (append .exe for Windows) |
target/release/PROJECT_NAME | Name of release executable for the project named PROJECT_NAME (append .exe for Windows) |
- Rust Language Website
- The Rust Programming Language Book - Online book documenting the Rust Language
- The Cargo Book - Online book describing Cargo (the Rust build system)
- Online Rust Langage Compiler - Online Rust compiler for learning Rust without having to install it.
- Rust Books
- TOML - Tom's Obvious Minimal Language - The Rust config file language (usually in the project root in a file called 'Cargo.toml')
- Rustlings - A series of short Rust programs used to test your knowledge of various Rust concepts.
- Cheat Sheet - A cheat sheet documenting many Rust features and links to explanations of them in the documentation.
- Rust by Example - A series of small Rust programs that explain different Rust features
- Read Rust A collection of links to various articles about Rust
- No Boilerplate - Youtube channel with various short videos on Rust
- Faster Than Lime - Blog with many articles on learning Rust
- No Boilerplate Discord
- The Little Book of Rust Macros
- Advent of Code - A series of programming exercises. It's not Rust specific but can be used for any language.
- Rocket.RS - Rust-based web framework