Chapter 1: Course Introduction & Setup

Development Environment Setup

Let’s get your Rust development environment ready. Rust’s tooling is excellent - you’ll find it more unified than C++ and more performant than .NET.

Installing Rust

The recommended way to install Rust is through rustup, Rust’s official toolchain manager.

On Unix-like systems (Linux/macOS):

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

On Windows:

Download and run the installer from rustup.rs

Rust on Windows supports two ABIs: MSVC and GNU. The rustup installer defaults to MSVC (x86_64-pc-windows-msvc), which is the recommended choice for most purposes. It requires the Visual Studio C++ Build Tools — the installer will offer to set these up for you. When prompted, select the “Desktop development with C++” workload.

Do not switch to the GNU toolchain (x86_64-pc-windows-gnu) unless you specifically need MinGW/MSYS2 interop. The GNU target requires a full MSYS2/MinGW installation on your PATH; without it, builds will fail with errors such as error calling dlltool 'dlltool.exe': program not found.

After installation, verify:

rustc --version
cargo --version

Understanding the Rust Toolchain

ToolPurposeC++ Equivalent.NET Equivalent
rustcCompilerg++, clang++csc, dotnet build
cargoBuild system & package managercmake + conan/vcpkgdotnet CLI + NuGet
rustupToolchain manager-.NET SDK manager
clippyLinterclang-tidyCode analyzers
rustfmtFormatterclang-formatdotnet format

Your First Rust Project

Let’s create a Hello World project to verify everything works:

cargo new hello_rust
cd hello_rust

This creates:

hello_rust/
├── Cargo.toml    # Like CMakeLists.txt or .csproj
└── src/
    └── main.rs   # Entry point

Look at src/main.rs:

fn main() {
    println!("Hello, world!");
}

Run it:

cargo run

Understanding Cargo

Cargo is Rust’s build system and package manager. Coming from C++ or .NET, you’ll love its simplicity.

Key Cargo Commands

CommandPurposeSimilar to
cargo newCreate new projectdotnet new, cmake init
cargo buildCompile projectmake, dotnet build
cargo runBuild & run./a.out, dotnet run
cargo testRun testsctest, dotnet test
cargo docGenerate documentationdoxygen
cargo checkFast syntax/type checkIncremental compilation

Debug vs Release Builds

cargo build          # Debug build (./target/debug/)
cargo build --release # Optimized build (./target/release/)

Performance difference is significant! Debug builds include:

  • Overflow checks
  • Debug symbols
  • No optimizations

Project Structure Best Practices

A typical Rust project structure:

my_project/
├── Cargo.toml           # Project manifest
├── Cargo.lock          # Dependency lock file (like package-lock.json)
├── src/
│   ├── main.rs         # Binary entry point
│   ├── lib.rs          # Library entry point
│   └── module.rs       # Additional modules
├── tests/              # Integration tests
│   └── integration_test.rs
├── benches/            # Benchmarks
│   └── benchmark.rs
├── examples/           # Example programs
│   └── example.rs
└── target/             # Build artifacts (gitignored)

Comparing with C++/.NET

C++ Developers

  • No header files! Modules are automatically resolved
  • No makefiles to write - Cargo handles everything
  • Dependencies are downloaded automatically (like vcpkg/conan)
  • No undefined behavior in safe Rust

.NET Developers

  • Similar project structure to .NET Core
  • Cargo.toml is like .csproj
  • crates.io is like NuGet
  • No garbage collector - deterministic destruction

Quick Wins: Why You’ll Love Rust’s Tooling

  1. Unified tooling: Everything works together seamlessly
  2. Excellent error messages: The compiler teaches you Rust
  3. Fast incremental compilation: cargo check is lightning fast
  4. Built-in testing: No need for external test frameworks
  5. Documentation generation: Automatic API docs from comments

Setting Up for Success

Enable Useful Rustup Components

rustup component add clippy       # Linter
rustup component add rustfmt      # Formatter
rustup component add rust-src     # Source code for std library

Create a Learning Workspace

Let’s set up a workspace for this course:

mkdir rust-course-workspace
cd rust-course-workspace
cargo new --bin day1_exercises
cargo new --lib day1_library

Common Setup Issues and Solutions

IssueSolution
“rustc not found”Restart terminal after installation
Slow compilationEnable sccache: cargo install sccache
Can’t debugZed has built-in debugging support
Windows linker errorsEnsure the MSVC toolchain is active (rustup default stable-x86_64-pc-windows-msvc) and Visual Studio C++ Build Tools are installed — see the Windows note above

Exercises

Exercise 1.1: Toolchain Exploration

Create a new project and explore these cargo commands:

  • cargo tree - View dependency tree
  • cargo doc --open - Generate and view documentation
  • cargo clippy - Run the linter

Exercise 1.2: Build Configurations

  1. Create a simple program that prints the numbers 1 to 1_000_000
  2. Time the difference between debug and release builds
  3. Compare binary sizes

Exercise 1.3: First Debugging Session

  1. Create a program with an intentional panic
  2. Set a breakpoint in Zed
  3. Step through the code with the debugger

Key Takeaways

✅ Rust’s tooling is unified and modern - no need for complex build systems

✅ Cargo handles dependencies, building, testing, and documentation

✅ Debug vs Release builds have significant performance differences

✅ The development experience is similar to modern .NET, better than typical C++

✅ Zed with built-in rust-analyzer provides excellent IDE support


Next up: Chapter 2: Rust Fundamentals - Let’s write some Rust!