Reminder: Your midterm project is due this Sunday at 11:59 PM!
Make sure you’ve tested your code locally and pushed all changes to GitHub
The automated grading system will run on Monday morning
If you have questions, reach out on Teams before Sunday
Welcome to a new frontier
For the next few weeks, we are shifting from Python to our second language, Rust
Rust is a modern, compiled language focused on three primary goals: performance, reliability, and safety
It has a steeper learning curve than Python, but it gives us the power to write incredibly fast and memory-efficient code, which is essential for systems programming, game development, and high-performance computing
Python is an interpreted language. An interpreter reads and executes your code line by line. This makes it flexible and easy to use, but it can be slower
Rust is a compiled language. A compiler translates your entire program into machine code—the raw instructions the computer’s CPU understands—before you run it
This ahead-of-time compilation is a major reason for Rust’s high performance. It catches errors early and optimizes the code for speed
Bonus: Compiled Rust programs don’t need a runtime or interpreter installed to run
cargo is Rust’s official build system and package manager, and it’s one of the language’s best features
It handles creating new projects, compiling your code, running your application, and managing external libraries (called “crates” in Rust)
Think of it as Python’s pip + pytest + black + mypy all rolled into one amazing tool!
Cargo is why Rust development feels so smooth and professional
Essential Cargo commands
Project management: - cargo new project_name: creates a new “Hello, world!” project - cargo init: initialize Cargo in an existing directory
Building and running: - cargo build: compiles your code (debug mode) - cargo run: compiles and runs in one command - cargo build --release: optimized production build
Development workflow: - cargo check: fast compile check (no executable) - cargo test: run all tests - cargo clean: delete build artifacts
cargo clippy - your personal Rust mentor: - Catches common mistakes and suggests better approaches - Over 500 lints for code quality, performance, and style - Like having a senior Rust developer review your code - Example: “you can simplify this code” or “this might panic”
cargo fmt - automatic code formatting: - Formats your code to match Rust community style - No more debates about spacing, indentation, or style - Run before every commit - keeps code consistent - Like Python’s black formatter
Your Rust development workflow
This is what professional Rust developers do:
Write code in your editor
cargo check - fast compilation check while coding
cargo clippy - catch issues and learn better patterns
cargo test - verify your code works correctly
cargo fmt - format code before committing
cargo run - try out your program
Pro tip: Run cargo check constantly. It’s 10x faster than cargo build!
A core concept in Rust is that variables are immutable by default. Once a value is bound to a name, you can’t change it. This helps us write safer code
To make a variable mutable, you must explicitly use the let mut keyword
This is the opposite of Python, where everything is mutable by default!
let x =5;// immutableletmut y =10;// mutabley =15;// this is allowed// x = 6; // this would cause a compiler error!
Characters: char, for a single Unicode character, denoted with single quotes
Compound data types
Rust has two primary built-in compound types for grouping multiple values
The tuple is a fixed-size collection of values of different types. Once declared, a tuple’s size cannot change
The array is a fixed-size collection where every element must have the same type
For dynamic sizing, we’ll learn about Vectors and HashMaps later
// A tuple with different typeslet my_tuple: (i32,f64,u8) = (500,6.4,1);// An array with five elements of the same typelet my_array: [i32;5] = [1,2,3,4,5];