The Rust programming language makes it possible to build fast reliable code, prevents segfaults, and guarantees memory safety, even while working across concurrent processes.
The course is split into seven parts, which give you a complete overview of why Rust is a great programming language. In the first couple of days, you’ll learn to install Rust on your system, discover its syntax, and see a library that utilizes the feature of trait-based generics and code reusability.
The Rust programming language makes it possible to build fast reliable code, prevents segfaults, and guarantees memory safety, even while working across concurrent processes.
The course is split into seven parts, which give you a complete overview of why Rust is a great programming language. In the first couple of days, you’ll learn to install Rust on your system, discover its syntax, and see a library that utilizes the feature of trait-based generics and code reusability.
On days 3 and 4, you’ll understand how Rust Lifetimes work by doing extensive compiler checking and learn to make your programs more interactive by accessing all the bits of the Rust environment. On day 5, you’ll learn about multithreading without data races with safe concurrency. Day 6, you’ll create a database, using your code to read and update while securing it with Bcrypt from various breaches such as SQL injection attacks.
By the end of the course, you’ll have built a mini-bank application that tracks users’ financial transactions over time, allowing them to view their history over time.
About the Author
Matthew Stoodley is a programming enthusiast and has been really excited to learn about Rust for it’s low level power and memory safety. He mostly uses it to build board games.
If you want to try them, or you are looking for a story teller, magician, illustrator, or a web developer, you can go to his website to get to know him better.
Understand how this series will help you learn Rust and how to use it effectively
Without Rust working on your machine it will be hard to test it out.
• Download the installer
• Run the installer
• Run your first Rust program
In order to write even the simplest program you have to understand the basic syntax
• Introduce functions and parameters
• Introduce variables and mutability
• Introduce printing syntax
Looping is core to programming anything useful
• Introduce “Loop” keyword
• Introduce “for” and “while”
• Introduce ranges and Iterators
Strings are a key mechanism for programs to interact with users and other programs.
• Learn the absolute basics on utf-8 and how rust handles that
• Learn about the difference between “&str” and “String”
• Learn to use String as function parameters
When dealing with complex systems it is helpful to organize your data in an orderly way
• Learn to define a struct
• Add methods to that struct.
• Call those methods on the struct
Handling data of different types can be challenging. Rust Enums provide a powerful mechanism for that.
• Learn to define an Enum
• Learn to match against different Variants
• Learn to add methods to the Enum
Error handling is tricky in any language. Rust provides two powerful classes to make that simple and safe
• Introduce Result and Error types
• Show some of their methods such as unwrap.
• Show how to use them in common cases
Make sure you have Rust installed and working, and understand some basic syntax
• Write a Rust program that greets everyone mentioned in the argument list whose name begins with “W”
Demonstrate how Traits are used for everything in Rust
• Create a new type
• Implement the “Add” Trait
• Show how this enables the “+” operator to work with it
In programming you often want to use other people’s libraries
• Include the Rand library
• Use the Rand library to generate random numbers
In order to define your own chosen behavior you need to define your own trait.
• Create a new trait
• Implement that trait
• Use that trait to do something
Some methods work well with any object as long as it meets a few requirements. Save rewriting the same code by making it Generic
• Introduce Generics
• Create a method that works a Generic type
• Call that method with specific concrete types
Some types, especially Collections, work will with any concrete type, as long as it meets a few requirements
• Create a new type that holds a Generic property
• Create a concrete object, with a specific type
• Call methods on that Generic type
All programming languages need to loop. In rust this is mostly done through the Iterator trait. We need to understand how to use it
• Introduce the Iterator trait
• Run a for loop
• Show what the for loop really does
There are some useful traits in the std library on rust. Knowing them makes programming in rust more efficient
• Introduce the Debug Trait
• Introduce the Clone Trait
• Introduce the Copy Trait
While Match on Result and Option can be powerful, it can be a lot of code to handle. We can make our code easier to read and write with the ‘?’
• Introduce the From Trait
• Show how the From trait can be used by ? To create convert between types
• Show how the? Uses the From type to make convert Errors
During this section we have been building a money library, how can we make it available for other people to use
• Introduce Crates.io
• Prepare our Crate (package) for upload
• Publish our crate
Make sure you have Rust installed and working, and understand some basic syntax
• Build a transaction library using the money type we created together
To understand Lifetimes, We need to understand why they matter
• Try returning a pointer to a deleted object
• Show how rust prevents that
• Explain what security this provides
In rust you can pss data around by copying it, or by pointing to it. We need to understand when to do each
• Show how we can borrowing an object means we can call functions without losing the data
• Show how we can change things we are pointing to
• Show how the compiler protects us from mutating data that is currently borrowed elsewhere
Sometimes we don’t know how big our data will be. We need to be able to handle that.
• Introduce the Box. An owned pointer.
• Use that Box to enable recursive type definitions
• Build a Linked List using Box
Some pointers well never be invalid. How can we tell the compiler not to worry about them
• Introduce the “static” lifetime.
• Show how we can create static pointers
• Show where static pointers can come from in natural code
Sometimes we need to have multiple items access the same pointer.
• Introduce the Reference Count Rc
• Show how we can clone an Rc Object
• Show how when the last item goes out of scope the data is finally freed
Make sure you have Rust installed and working, and understand some basic syntax
• Build a binary Tree of names
• Traverse it tracking your position with pointers
Operating System Environment Variables can hold useful information often about where to find files, We need to be able to read that.
• Show how to access environment variables
• Show the problems with testing against environment variables
• Show some testing techniques for working around, things outside your control
When working on a system with many programs available sometimes it us useful to get them to do the work for you
• Show how we can make system Calls
• Show how this library uses the Builder Pattern.
• Call a program passing command line arguments to it
Sometimes our program will need to act as a mediator between two other programs
• Show how pipes can be taken from programs output.
• Show how we can feed data into a programs input
• Call two programs and pass the output of one, into the other
The filesystem is a vital part of any operating system, we need to be able to access and save our own data, and sometimes other data
• Show how to open and read files
• Show how to write files
• Read one file, make changes and write it to a result
Make sure you have Rust installed and working, and understand some basic syntax
• Read a list of transactions, between users
• Write a file showing the final amount each user has
Modern Processors have multiple cores, each working simultaneously.. How can we take advantage of that to make our programs run faster
• Show how to launch a new thread
• Show how to wait for another thread to complete
• Show how to get the access the return result of a completed thread
Sometimes we need to tell another thread to do something, or pass other data to it so it can complete its job.
• Show how channels pass data between threads.
• Show how channels can be cloned
• Show how a when a channel is dropped, the receiver closes
Often, rather than use a channel, it can be much simple to share a single data item.
• Introduce Mutex, and show how it guarantees only one thread can access its data at a time
• Introduce Arc, and show how this enables us to Clone and Reference Count our Mutex
• Write a program that relies on a single mutex
Sometimes we have a lot of work to do that could be done concurrently. However creating a new thread for each task is expensive.
• Introduce the idea of a thread pool, or group of threads that wait for a task to do
• Introduce the idea of a job queue that we can add tasks to
• Show how different threads can take from that Job Queue, and quit when the queue is empty
Lots of jobs can be broken up into parts that do not need to interact with each other. Is there a simple way to break them apart?
• Show how to use Rayon to easily parallelize an iterated task
• Show how Rayon uses it’s Join method, internally to do this
• Write our own Parallel iterator using the Join method
Write a program that simulates 10 different users:
• In separate threads
• Creating an account
• Making Sending money to another user
Most Web Applications have a Database of some form at their back end. How can we handle that in rust?
• Download and install Sqlite
• Setup a database to handle transactions
• Test the database from within sqlite3
To add users and transactions we need to be able to edit our database
Show how to create a connection to Sqlite
Show how to prepare an edit statement
Show how to bind variables to it, and how to call the final edit command
To read a user’s balance we need to read a list of transactions out of the database.
Show how to prepare a read statement.
Show how to read rows from the returned response
Compile the rows into users balance
Create a command line database application allowing users to
Login
Pay someone
Check their balance
Rocket is a powerful Framework for creating Web applications. But it has a few requirements to be able to run on a normal system.
Introduce and install Nightly Rust.
Write a simple Rocket web server
Test our server’s response in a browser
Oten you need the html of your website to change dynamically.
Introduce the Maud html Generation system that uses Rust Macros, to generate extremely fast dynamic html.
Generate an html page with dynamic content
Test the contents of that page are what we want to see
To enable logins to last, we need a mechanism to store each user and associate some “cookie” or data item to them.
Create a Session List type that uses a Mutex and HashMap to store session data
Write methods for putting and getting sessions from this without needing “mut” externally
Test this actually creates a session correctly
From a html webpage we can send form data to a server, but how can we access it in rust.
Show how form data can be loaded into a Rocket function
Write a Rocket function that loads the Form Data into a user request
Create a new User in the database with that name
Http Cookies enable us to maintain a consistent session by tracking a small amount of data.
Show how to access a cookie and state object in Rocket
Use the cookie to store a SessionId, and access a user id
Use the UserId to make payments and check their balance
Create a mechanism for new users to Sign up, to Mini-Bank
Allow users to see a complete transaction history
Allow users to Logout
Add a session timeout
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.