Skip to product information
1 of 1

Event

Ultimate Rust Foundations - Hybrid Training - November 2023 Session

Ultimate Rust Foundations - Hybrid Training - November 2023 Session

Regular price $595.00
Regular price Sale price $595.00
Sale Sold out
Ticket Type

Ultimate Rust Foundation - Five Deep Dives on Rust

The Ultimate Rust Foundations class starts with an introduction to Rust, and the benefits you gain by using it as a foundation, and within your existing ecosystem.

By completing this course, you will acquire a strong foundation in Rust programming, system-level concurrency, memory management, and building network services, making you proficient in various aspects of Rust development.

When: Starts on Wednesday, November 1st, and ends on December 13th

Schedule:

Modules

01: Getting Started with Rust

02: Fearless System Thread Concurrency

03: Async/Await Concurrency

04: Managing Memory and Resources

05: Building Network Services

 **Important:** Upon completion of each Q&A session, there will be a video recording available of each for 3 months. An email with instructions to access them will be sent.

Module 01: Getting Started with Rust

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

Difficulty: Low

This module 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

 

Module 02: Fearless System Thread Concurrency

 

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.

 

Module 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.


Module 04 - Managing Memory and Resources

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.

 

Module 05 - Building Network Services

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.


 

View full details