This course will teach you the fundamentals of Rust, a modern programming language that has the both the power of native code as well as the safety of some managed languages. In this course you will learn the following:
This course will teach you the fundamentals of Rust, a modern programming language that has the both the power of native code as well as the safety of some managed languages. In this course you will learn the following:
This course, like all my other courses, will be supplemented with additional lectures based on participants' requests.
Welcome to the course! Now, for a taste of things to come...
Let's get started by installing Rust.
The obligatory Hello, World! demo, made with Rust.
Learn about Cargo, Rust's own project and dependency management system.
Note that Cargo configures your folder to be a Git repository and creates a .gitignore file.
A discussion of the free IntelliJ IDEA Community IDE and how to set it up to work with Rust.
An overview of bits, bytes and the sizes of numbers that can be represented in a typical programming language.
Some preliminaries before we get started. Here we discuss the application entrypoint — the main function; also we discuss functions in general and the println! macro.
Learn about boolean, integral, floating-point types and the char type.
A description of some of the Rust operators such as +, <=, && and so on.
A discussion of scopes and how variables in inner scopes can shadow outer variables.
Global values that are unlikely to change.
Learn about the distinction between the stack and the heap,
A demonstration of how to debug Rust applications in CLion. Debugging skills are critical to successful Rust application development, so pay attention!
Learn about the if statement, including some unusual syntax. (And no, Rust does not have a ternary ?: operator.)
A look at conditional and unconditional loops.
for loops... also very unusual.
A look at match which lets you pick the right option based on matching input plus additional conditions. Very powerful!
A simple example using control flow constructs.
A very important topic! Structs let us keep related data together in a single object.
(Note: there is no concept of constructor in Rust.)
A traffic light can be red, green or blue. How to best represent this information in a program?
With the release of Rust 1.19, we've got a new data type called a union. A union can define several fields of different type, but they all occupy the same memory. Unions are very useful for C interop, among other things.
Here we talk about a very useful type called Option<T>, the None/Some(x) duality, and also discuss the if let and while let declarations.
Learn how to store multiple values of any type in a single data structure as well as how to go over those values.
A slice is a read-only view into an array or a vector.
Learn about tuples, their destructuring and indexing. (Yes, destructuring is a word.)
Now that we know more about various data structures, let's revisit the match keyword and discuss pattern matching, an extremely powerful technique.
Learn about generic structures.
A look at the key Rust collections.
A vector is like an array, but resizeable. Also behaves like a stack.
A key-value store that allows fast access and update/upsert operations.
A data structure that represents a mathematical set.
Some notes about iterators in Rust.
Strings are used to store text (i.e., sequences of characters). Learn about both str and String. Both are valid UTF-8 sequences of bytes.
Why does str exist? Because an ordinary slice of a String is effectively a slice of Vec<u8>, which is not very useful.
Learn about the format! macro.
A tiny game.
We've already met the function main, but now we discuss functions at large.
A struct can have not just fields but also its own functions!
How do you store a function in a variable? How do you pass a function to some other function? These concerns are addressed with closures (a.k.a. lambda functions).
Functions that return functions. Don't worry, it's not as scary as it sounds.
Traits let you specify that a type must possess certain aspects.
Three forms of syntax for passing traits as parameters.
A look at the Into trait, which helps with automatic conversions.
A way of giving your structs destructors.
Learn how to define the behavior of operators such as + for your own structs.
One of two possible forms of dispatch. Static dispatch is when the compiler knows exactly which realization of function to call.
What if the compiler doesn't know which trait implementation to call?
So given that static dispatch is faster, why would we want to use dynamic dispatch, anyway?
You cannot make vectors of different objects. But if you really need to, you can make a vector of enum cases or of pointers (&, Box, Rc, etc.)
Learn about ownership, move semantics and move-able types.
We finally get to look at explicit use of lifetime specifiers. Woo-hoo!
A look at how lifetimes are defined in implementations of structs.
In addition to ownership/borrowing, Rust also supports the notion of reference-counted variables. These are somewhat easier to share. The approach is similar to C++'s shared_ptr/unique_ptr.
A reference-counted variable (Rc) is safe to share around within a single thread. But what if we want to share it around in multiple threads? How can we ensure its pointer count is actually safe from concurrent modification? That's what the Arc class is for.
Arc protects the reference count, but it doesn't protect the variable itself, so concurrent modification of the variable will still be prohibited by the Rust compiler. How can we get concurrent code that mutates the variable to work? One option is to use a Mutex.
In Rust, circular references are difficult to get right.
The first step on the road to concurrency is to learn how to spawn a thread of execution and then wait on it to complete (a.k.a. join).
Let's try using a crate that's available on crates.io.
Let's build our own crate out of separate modules... and then consume it!
Now that we know about functions, we can write unit and integration tests.
Learn how to document your own code.
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.