Learn to Code with Rust is a comprehensive introduction to programming in Rust, one of the fastest-growing programming languages in the world. Rust powers codebases in companies and products like Amazon, Microsoft, Firefox, Discord, and more. It is used in a variety of disciplines including web development, CLI programs, build tools, and databases.
Over more than 50 hours of video content, we’ll tackle the language from A to Z, covering everything you need to know about Rust to be an effective developer.
The course is jam-packed with:
50+ hours of video, with new content added frequently
Multiple-choice quizzes
Coding challenges and projects
Section reviews
Learn to Code with Rust is designed from the ground up to take you from novice to professional. Complete beginners are welcome; no prior experience is needed! Over 300+ videos, we’ll work our way from language fundamentals to advanced features. Topics covered include…
Setup & Installation
Variables
Data types
Functions and Methods
Control Flow
Ownership and References
Slices
Structs
Enums
Generics
Option and Result Enums
Vectors
Project Structure
Strings
Hash Haps
Error Handling
Traits
Lifetimes
Closures
Iterators
…and more!
Throughout the entire journey, I’ll be coding alongside you step by step in the code editor. You’ll also be able to test your knowledge through numerous coding challenges, quizzes, and written assignments.
Rust is known to be a challenging language to learn. For many concepts, I had to browse through different books, articles, and videos to understand what was happening. My hope here is to demystify the concepts and make it easier for new students to learn the language.
Thanks for checking out the course!
Welcome to Learn to Code with Rust. Rust is a systems programming language optimized for speed and safety. In this lesson, we'll introduce the language's features, its history, and some fun tidbits about its community.
Source code is the code that we developers write. The Rust compiler is a program that translates our source code into an executable program called a binary or a binary executable. This lesson also offers an introduction to the compiler and general programming advice to reduce your chance of errors.
Access the Terminal application, a command-line interface for interacting with the operating system. Learn some basic commands for file system navigation, printing contents, and more.
XCode Command Line Tools is a dependency (requirement) of installing the Rust compiler. In this lesson, we set up the Command Line Tools through the Terminal.
In this lesson, we'll install Rust on macOS operating systems. The installation also includes the rustup tool for managing Rust and the cargo tool for managing projects.
Visual Studio Code (VSCode) is a free text editor for writing source code in various programming languages. In this lesson, we install the text editor and several extensions for Rust development.
In this lesson, we run a command from VSCode's Command Line Palette to ensure the code command works from the Terminal. We can use code . to open up the current directory.
Access the PowerShell application, a command-line interface for interacting with the operating system. Learn some basic commands for file system navigation, printing contents, and more.
Windows has 32-bit and 64-bit versions; you'll need to know your operating system version to setup Rust. This video walks you through finding out the version; memorize the value.
In order to setup Rust, we'll need to install Visual Studio, a text editor from Microsoft which includes a dependency called the Visual Studio C++ build tools. This video walks you through the download and installation process.
In this lesson, we'll install Rust on Windows operating systems. The installation also includes the rustup tool for managing Rust and the cargo tool for managing projects.
Visual Studio Code (VSCode) is a free text editor for writing source code in various programming languages. In this lesson, we install the text editor and several extensions for Rust development.
Use the rustup tool to download the latest version of Rust, uninstall Rust, and access its documentation in your browser.
Git is a version control system for saving the checkpoints of a project. This lesson walks you through the basics of Git including installation.
The Cargo command-line tool creates a starter Rust project. In this lesson. we create a new project with a src/main.rs file. We also discuss the differences between binary crates and library crates.
Hello World is a rite of passage in the programming community; the first goal in any language is to output the text "Hello World" to the screen. In this lesson, we discuss the basic constructs of a Rust program that allow us to accomplish this goal: functions, blocks, the println! macro, parameters, semicolons, and more. We also learn how to use the rust-analyzer's Run button to compile and run the program directly from VSCode.
In this lesson, we compile our Rust project from the command-line using the cargo build command. We then run the executable which will be different between macOS and Windows operating systems.
Use the rustfmt and cargo fmt tools to format the Rust code in a single file vs. a whole Cargo project. Formatting does not change the structure of the code, only its aesthetics.
This lesson discusses the two modes of compilation that cargo build can utilize: debug and release. Debug is built for developers debugging while release is built for the final program/end user. We also learn the cargo clean command to delete the compiled executables.
Utilize the cargo run command to build and run the source code with a single command.
Use the cargo check command to check the source code for violations without compiling the program. The command tends to be faster because of the decreased amount of effort.
A comment is a line that is ignored by the Rust compiler. Developers use it to leave notes, descriptions, metadata, etc. In this lesson, we introduce the multiple ways to declare comments in Rust.
Test your knowledge of the section's concepts in a project.
See a solution to the previous lesson's project.
Download the course materials for the course from GitHub. You can either use the Git command line tools to fetch the content or download the ZIP file manually.
Complete a multiple-choice quiz to review the concepts introduced in this course section.
Review the concepts introduced in this section including the Rust compiler, the cargo CLI tool, the main function, comments, and more.
Open the project for this section and introduce the concepts we'll be learning!
A variable is a name assigned to a value in the program. In this lesson, we declare variables, use them in calculations, and observe Rust's data type inference.
Our strings can incorporate dynamic content with curly braces. This feature is called interpolation. In this lesson, we explore a variety of syntax options for injecting the content into our strings.
Pass positional arguments to the println! macro. Rust assigns each argument after the string a numeric position in line. The caveat is that the count starts at 0.
Use an underscore to inform the compiler that a variable is intentionally unused. We'll be encountering plenty of unused data throughout the course.
Variables are immutable by default, which means incapable of change. We need to use the mut keyword to mark each piece of data as mutable (capable of change).
Every Rust compiler error has a unique error code. In this lesson, we'll see how to find documentation for each error in both the Terminal and the online Rust error codes index.
Variable shadowing re-declares a variable, allowing us to reuse the same name with a different type. The most common usecase for variable shadowing is performing one or more data type transformations on a starter value; variable shadowing enables us to keep the same name for the data.
A scope is the boundary or region in which a name is valid. Scopes are connected to blocks. A block is the area between a pair of opening and curly braces. In this lesson, we trace the scope and existence of various variables declared in the main function.
A constant is name that we assign to a value. A constant can never change its value throughout the program. Its value and type must be known at compile time.
A type alias is a nickname assigned to an existing type. A type alias can provide some additional context on what a type represents in the program. We use the type keyword followed by the type name, an equal sign, and the original type.
A compiler directive is an annotation that instructs the compiler how to parse the code. In this lesson, we introduce the allow directive for permitting code that the compiler would otherwise express concern about. We learn how to declare directives for lines, functions, and files.
Test your knowledge of the section's concepts in a project.
See a solution to the previous lesson's project.
Complete a multiple-choice quiz to review the concepts introduced in this course section.
Review the concepts introduced in this section including variables, mutability, interpolation, error codes, scopes, constants, type aliases, and more!
Open the project for this section and introduce the concepts we'll be learning!
Dive into Rust's basic integer and floating point types. Understand the memory units of bits and the ranges of various data types.
Transition back into VSCode and practice annotating various integer types. See how the compiler alerts you to the limitations of a type.
Use the underscore character to visually separate the digits in an integer.
usize and isize are aliases for existing integer types in Rust. The type will depend on the architecture of the operating system that the executable is being run on. For example, the usize unsigned integer is equivalent to a u32 on a 32-bit system and a u64 on a 64-bit system.
A string is a piece of text. String literals are strings whose values the compiler knows at compile time. We declare strings in double quotes. In this lesson, we practice creating strings and introduce special characters like n and t. We also explore the benefits of raw strings.
A method is a function that lives on a value. We invoke a method with a dot, the method name, and a pair of parentheses. Methods may accept arguments.
In this lesson, we'll learn about Rust's two floating point types. Floats represent decimal numbers, numbers with a fractional component. Rust has two float types: f32 (32-bit) and f64 (64-bit). f64 offers double the precision of an f32.
Format the printed representation of a floating-point number using the format specifier (:) and the precision to output. The precision is the number of digits after the decimal point.
Utilize the as keyword to convert one numeric type into another. The technical word for this conversion is casting.
Explore the operators for common mathematical operations like addition, subtraction, division, multiplication, and remainder.
Augmented assignment operators are symbols that perform an operation on a variable's current value and overwrite the variable with the new value. For example, += adds a value and overwrites the variable with the sum.
A Boolean type can only be one of two values: true or false. It models a statement of truth. In this lesson, we declare some Booleans and explore some methods that return them.
Use the ! symbol to invert a Boolean. A true becomes false, and a false becomes ture.
Practice with the equality and inequality operators. The equality operator accepts two operands and checks whether they are equal. The inequality operator checks whether the two operands are not equal.
Use the && operator to validate that multiple Booleans evaluate to true. This models a scenario where multiple independent conditions must be met in order for something to be true.
Use the || operator to validate that either one of Booleans evaluate to true. This models a scenario where at least one of several independent conditions must be met in order for something to be true.
A character type represents a single Unicode character. It may represent common alphabetic characters in 100+ languages but can also represent an emoji. In this lesson, we explore some of the pitfalls of characters in programming.
An array is a fixed-size collection of homogenous data. Arrays store a sequence of values in order.
Let's declare some arrays and explore how the Rust compiler infers their types.
Rust assigns each element within an array an order in line. The count starts from 0. In this lesson, we learn how to both access and overwrite an element at an index position.
A trait is a contract that requires that a type support one or more methods. The Display trait requires a method on the type that will return the type as a user-friendly string. Every time we use {} interpolation syntax, we rely on the Display trait implementation on a type.
In this lesson, we introduce the complementary Debug trait. While Display is for human-readable output, the goal of Debug is to format a type into a programmer-facing string for debugging. We use the :? format specifier to print a value in Debug format.
In this lesson, we'll learn another macro called dbg!, which is short for "debug". The dbg! macro prints and returns the line of code we wrote and its output. It offers a nice shortcut to get the Display trait output of a value.
Like an array, a tuple is a collection type that can contain multiple elements, each of which is an assigned an index position reflecting its order in line. The difference between the two data types is that a tuple supports different types for the values. An array is homogenous, which means all of its elements must be of the same type. A tuple does not have that requirement, so it can store elements of different types.
The Range type represents a sequence or interval of consecutive values. For example, a range can represent the sequence of numbers between 15 and 23, or the lowercase characters between the letter 'b' and the letter 'h'.
A generic represents a type argument. A generic is a placeholder for a future type that has the potential to vary. Generics enable flexibility in the design of functions and types because the code is not bound to a single type.
Test your knowledge of the section's concepts in a project.
See a solution to the previous lesson's project.
Complete a multiple-choice quiz to review the concepts introduced in this course section.
Review the concepts introduced in this section including integers, floats, strings, tuples, arrays, booleans, methods, generics, the Display and Debug traits, and more!
Open the project for this section and introduce the concepts we'll be learning!
A function is a sequence of steps to be executed in order. It’s a procedure that encapsulates some logic. The power of functions lies in their ability to capture a reusable collection of instructions. In this lesson, we declare some simple functions and invoke them from main.
In this lesson, we'll learn how to define function parameters. A parameter is a name for an expected input. When a function is invoked, we are required to pass in a concrete value for that parameter, which is called an argument.
A return value is the output of a function. It is what the function gives back to the caller, which is what invoked the function in the first place. In this lesson, we use the return keyword to specify an explicit return value.
A Rust function implicitly returns the last evaluated value from its function body. In this lesson, we practice using this implicit return syntax.
This lesson introduces a special type called the unit. A unit is an empty tuple, a tuple without values. Functions in Rust return a unit if no return value is explicitly or implicitly specified.
In this lesson, we show to declare an evaluation block inside a function body. Rust evaluates the contents of the block and "returns" the last value it produces; its a similar concept to functions but one fully contained within a function body. The block creates an independent execution environment for isolating a collection of related code.
Test your knowledge of the section's concepts in a project.
See a solution to the previous lesson's project.
Complete a multiple-choice quiz to review the concepts introduced in this course section.
Review the concepts introduced in this section including functions, parameters and arguments, implicit and explicit return values, units, blocks, and more!