Rust
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Ownership and Borrowing
-
Section 4: Structuring Data
-
Section 5: Collections and Error Handling
-
Section 6: Traits and Generics
-
Section 7: Concurrency
-
Section 8: Building for the Web
-
Section 9: Memory and Performance
-
Section 10: More Standard Library and Ecosystem
-
Section 11: Advanced Rust
-
Section 12: Rust for Systems and WebAssembly
-
Section 13: Tooling and Best Practices
-
Section 14: Data Structures and Algorithms in Rust
-
Section 15: Practical Projects
-
Section 16: Interview Practice
-
Section 17: std::collections In Depth
-
Section 18: std::io and std::fs In Depth
-
Section 19: std::net
-
Section 20: std::option and std::result In Depth
-
Section 21: std::iter In Depth
-
Section 22: std::sync In Depth
-
Section 23: std::string and std::str
-
Section 24: Cargo and Crates.io Ecosystem
-
Section 25: Popular Crates Ecosystem
-
Section 26: Rust Memory Model Deep Dive
-
Section 27: More Practice Exercises
-
Section 28: More Interview Practice
-
Section 29: Async Rust Deep Dive
-
Section 30: Tokio Ecosystem In Depth
-
Section 31: Error Handling Ecosystem Deep Dive
-
Section 32: Serde In Depth
-
Section 33: Web Development with Rust Deep Dive
-
Section 34: Database Access Ecosystem
-
Section 35: Rust for Embedded Systems Deep Dive
-
Section 36: Rust Macros In Depth
-
Section 37: Advanced Trait System
-
Section 38: Unsafe Rust In Depth
-
Section 39: Rust CLI Development
-
Section 40: Testing Ecosystem Deep Dive
-
Section 41: WebAssembly Deep Dive
-
Section 42: Rust Design Patterns
-
Section 43: More Data Structures in Rust
-
Section 44: Final Practice Projects
-
Section 45: Rust Performance Optimization
-
Section 46: Rust Ecosystem Tooling
-
Section 47: More Interview and Review
1: Installing Rust and Cargo
I've just spun up a fresh development environment, and before we can actually write any code, we need the tooling. I usually start by checking if anything is already pre-installed on the system, just so I don't waste time downloading things I already have.
Testing the waters
$ rustc --version
bash: rustc: command not found: rustc
Right. Nothing. In some enterprise environments, you might find a version of Rust already there, but it's usually outdated. If it had returned something like rustc 1.40.0, I'd be worried because the Rust ecosystem moves fast. We want the latest stable release to ensure we have the newest language features and the best compiler optimizations.
Letting rustup take the wheel
Instead of downloading a binary manually from a website—which is a nightmare to update later—I use rustup. It's the toolchain manager for Rust. It doesn't just install the compiler; it lets me swap between stable, beta, and nightly versions of the language without breaking my system.
I'll run the standard installation script:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
I'm choosing the default installation here. It asks a few questions, but for 99% of us, the "Proceed with installation (default)" option is the right call. While it's running, it's grabbing rustc (the compiler), cargo (the build tool and package manager), and rustdoc (the documentation generator).
The "Command Not Found" dance
Now, I'll try to check the version again, expecting a victory.
$ rustc --version
bash: rustc: command not found: rustc
Wait, what? I just installed it. This is the part that trips people up. The installer puts the Rust binaries in a hidden folder in our home directory (~/.cargo/bin), but my current terminal session doesn't know that folder exists yet. The installer told me to "source" the environment, but I'll just do it manually to show you what's happening.
$ source $HOME/.cargo/env
$ rustc --version
rustc 1.76.0 (07d945517 2024-02-04)
There we go. Now the shell knows where to look. If you're on Windows, you'd usually just need to restart your PowerShell or Command Prompt for the PATH changes to kick in.
Hitting the linker wall
I have the compiler, but Rust doesn't work in a vacuum. It needs a "linker" to actually package the compiled code into an executable. To test if my system is actually ready, I'll try to create a tiny project using Cargo.
$ cargo new build_test
$ cd build_test
$ cargo build
On a fresh Linux install, this is where I usually hit a wall. I'm seeing a giant wall of red text ending in error: linker 'cc' not found. This happens because Rust leverages the system's C linker. If you don't have build-essential tools installed, Rust can compile the code but it can't "link" it into a final program.
I'll fix this by installing the base development tools for my OS. On Ubuntu/Debian, that's:
$ sudo apt update
$ sudo apt install build-essential
Now, let's try that build again.
$ cargo build Compiling build_test v0.1.0 (/home/user/build_test) Finished dev [unoptimized + debuginfo] target(s) in 0.42sSuccess. We have
rustupmanaging our versions,rustcdoing the heavy lifting, andcargoorchestrating the whole process. We're officially ready to write some actual logic.
📋 Practical Task
Validating the Toolchain with a Cargo Project
To ensure your installation is fully functional and your system linker is configured correctly, perform the following steps:
- Open your terminal and use Cargo to create a new project named
toolchain_verify. - Navigate into the project directory.
- Run the command
cargo check. This command is faster thancargo buildbecause it only verifies that the code compiles without actually producing a binary. - Run
cargo runto compile and execute the default project code. - Confirm that you see the output
Hello, world!in your terminal. If you encounter a "linker not found" error, install the build-essential (Linux) or C++ build tools (Windows) and try again.
There are no comments for now.