Ultimate Rust Foundations: Five Class 4-Hour Deep Dives on Rust

Five Class 4-Hour Deep Dives on Rust is a series of 4-hour classes that can be taken independently or as a group, and provide a deep dive into a useful topic.

  • When: Starts every Thursday, from May 18 ends June 15th

  • Time: 11 am EST to 3 pm EST

  • Note: When purchasing your ticket, you are only eligible to select the amount of classes pertaining to the number of sessions you are looking to purchase. You may select which classes you’re looking to attend, they do not have to be consecutive.

    • ex: 2 sessions purchased - Class 01 & Class 04

    • ex: 3 sessions purchased - Class 02, Class 04, Class 05

Sessions

Class 01: Getting Started with Rust: May 18th, 2023

Class 02: Fearless System Thread Concurrency: May 25th, 2023

Class 03: Async/Await Concurrency: June 1st, 2023

Class 04: Managing Memory and Resources: June 8th,2023

Class 05: Building Network Services: June 15th,2023

Important: Upon completion of each session, there will be a video recording available for download within 48 hours. An email with instructions to access them will be sent.

Classes Curriculum

Class 01: Getting Started with Rust

When: May 18th, 2023

Prerequisites: A computer with Rust installed (from rustup.rs), a text editor/IDE - ideally with Rust Analyzer installed.

Difficulty: Low

This class is for the beginner to Rust, looking to get started. It is condensed from “Ultimate Rust: Foundations”. The class offers enough to take you from “hello world” to writing simple Rust programs. The class is intended to be interactive.

  • Setup (Ensure your IDE, Rust, and toolchain are working properly)

  • “Hello World” - the basic starting point, using “cargo new” to start a project.

    • Rust syntax overview
    • Quick dive into the parts of “cargo new” that you may not expect: git and other SCM integration.
  • Cargo Workspaces

    • Group your code together to save disk space and speed up compilation.
  • “Hello Library”

    • Create a new library with “cargo new –lib”.
    • Create and export a function (explain “pub”)
    • Use the library from our first program
  • Text Input and Unit Testing

  • Enumerations, and Pattern Matching

  • Structures

  • Arrays, Vectors, Slices and Iterators

  • HashMaps

  • Move by Default

  • Using libraries from Cargo: JSON serialization

Class 02: Fearless System Thread Concurrency

When: May 25th, 2023

Prerequisites: A working Rust installation, a text editor/IDE with Rust Analyzer. Basic understanding of Rust syntax.

Difficulty: Low-Medium

This class discusses concurrency at a system-thread level. System threads carry a higher overhead than “green” threads (e.g. Go routines, node.js or Rust async) but offer a lot of flexibility and control over program operation. This class is intended to be interactive.

  • What is a system thread?

    • System threads have their own stack and are scheduled by the operating system.
    • System threads are great for long-running tasks
    • Raw system threads are not a good choice when you need thousands of tasks.
    • Rust and Race Conditions.
  • Hello Threaded World

  • Create a simple “hello world” program that spawns a number of threads, each of which greets the user - and waits for all of the threads to finish before terminating.
  • Returning data from threads

    • Replace greeting the user with performing a calculation based on input, and returning a result.
    • Combine the results and display the result.
  • Safely Sharing Data between Threads

    • Using Mutex, RwLock to “lock” data.
    • Using DashMap for lock-free data sharing at very high speed.
  • Sending Messages to Threads

    • The “multi-producer, single consumer” channel type.
    • Other channel types with crossbeam.
  • Simplified Threads with Rayon

  • Rayon automatically builds a thread pool, and can spawn “tasks” within the thread pool. The threads are always running, so creation overhead is limited.

Class 03 - Async/Await Concurrency

When: June 1st, 2023

Prerequisites: A working Rust installation, a text editor/IDE with Rust Analyzer. Basic understanding of Rust syntax. It is recommended but not mandatory that you also take the System Threads class.

Difficulty: Low-Medium

  • What is async/await?

    • Popularized by node.js, and also used by Go routines.
    • Tasks run cooperatively, yielding at “await” points.
    • Idea for input/output, in which you are often waiting for an external resource.
    • Async is not threading! You can run single-threaded, or have multiple task queues within threads. You can mix and match as needed.
  • Hello Async

    • Create a Tokio (a popular Rust async framework) “hello world” that uses asynchronous functions.
    • Using “join” to spawn multiple tasks at once and wait for all of them - on a single thread.
    • Use “select” to spawn multiple tasks at once and wait for one of them - automatically canceling the others (and cleaning up!).
    • Use “spawn” to run a task on a different thread if possible (but still async), providing both threaded concurrency and green threading.
  • The Problem with Blocking

    • Add a “sleep” command, and accidentally pause the world.
    • Instead, use Tokio’s “sleep” command that is friendly to cooperative multitasking.
    • If you really need to block, use “spawn_blocking”
  • Async Channels

    • Communicate between tasks with MPSC and Broadcast channels.
    • The “Fan Out” pattern: controllers receive messages and spawn additional tasks.
    • RAII: You don’t need to close the channel.
    • Combining Threads and Green Threads
    • Sometimes, you want total control over how many resources are allocated to a task.
  • Create a new skeleton program.

  • Spawn a thread.

  • Attach a single-threaded Tokio context to it and run tasks in the thread.

  • From a second Tokio context, broadcast messages to the first.

Class 04 - Managing Memory and Resources

When: June 8th,2023

Prerequisites: A working Rust installation, a text editor/IDE with Rust Analyzer. Basic understanding of Rust syntax.

Difficulty: Medium

One of Rust’s primary advantages over “managed” languages is that you can manage memory yourself. This can provide great improvements in overall performance, predictability, and stability. It can also be confusing to anyone not used to managing memory. This class is mostly interactive but has some demonstrative learning.

  • The Rust Memory Model

    • Stack vs Heap
    • The Borrow Checker’s Golden Rule Anything can be referenced read-only as often as you like. Anything can be referenced mutable exactly once at a time.
  • Lifetimes No dangling references The need to prove that a reference is still valid when you use it.
  • Copying, Moving, Cloning and References

    • Rust is “move by default” (except on Copy types). “Use after move” won’t compile.
    • Primitive types may be “copied”. ONLY if they implement “Copy”.
    • Types may be “cloned”, ONLY if they implement “Clone”. Clone does a deep-copy, including cloning children.
  • RAII: Resource Acquisition is Initialization

    • Stack allocation is basically automatic.
    • You can implement “drop” on (almost) anything to have a destructor fire when a variable leaves scope. Don’t forget to handle Ctrl-C if cleanup is required!
    • Drop is hierarchical Implement a type that stores a vector of types. Drop the vector. Each destructor is fired.
  • Heap Allocation

    • Vectors are automatically on the heap.
    • Using Box as a smart pointer.
    • Using Box for full virtual table implementation—if you really need it.
  • Arenas and bulk allocation

  • Using different allocators

    • Jemalloc - high performance, instrumentable allocation.

Class 05: Building Network Services

When: June 15th,2023

Prerequisites: A working Rust installation, a text editor/IDE with Rust Analyzer. Basic understanding of Rust syntax. You need to have sqlite3 installed on your computer. It is recommended that you take the Green Thread concurrency class first.

Difficulty: Low-Medium

Network services are the bread and butter of most corporate networks. Rust can get you up and running very fast, giving you fast, stable and predictable services in very little time. This class is very hands-on.

  • Introduction
  • Build a webserver with Axum
    • Hello World
    • Implement a GET service that returns JSON
    • Use sqlx to obtain data from a database.
  • Build a TCP Server with Tokio
  • Build a simple TCP server and client in a single executable.
  • Use sqlx to obtain data from the same database.
  • Do some benchmarking.

About The Instructor

Herbert Wolverson

Herbert has been developing software professionally for more than 20 years. Starting with Pascal, and then moving onto C and C++, Herbert has developed custom applications ranging from web-server filters to games. Herbert is the author of Hands-on Rust and Rust Brain Teasers.