IS 4010: Application Development with Artificial Intelligence
Week 09: Welcome to Rust
Brandon M. Greenwell
Session 1: why Rust?
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 supports high-performance, memory-efficient programs for domains such as systems programming, game development, and scientific computing
Python is commonly executed by an interpreter and virtual machine. Its dynamic runtime makes experimentation convenient but adds overhead for some workloads
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 uv + pytest + formatter + type checker rolled into one tool!
Cargo provides one interface for the build, test, run, and dependency workflows used in this course
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 - Provides automated feedback based on established Rust lints - 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
Use this repeatable development loop:
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
Practice: Use cargo check for quick compiler feedback, then run the full required checks before submitting.
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];