πŸ› οΈRust Workshop

Please fill this out in a Word document and submit to Bridgebuildersdao@gmail.com to gain access to our live workshops and be notified when we have them.

Rust Workshop

Finding students

Questionnaire

  • Rate your knowledge in the following programming languages from 0 (know nothing) to 5 (fluent):

    • JavaScript

    • TypeScript

    • Python

    • Ruby

    • C++

    • C

    • Scala

    • Kotlin

    • Haskell

    • Swift

    • Objective-C

    • Java

    • Go

    • Elixir

    • Other

  • How many years have you been programming?

  • Have you done more backend or frontend development? If frontend, are you hoping to use Rust on the frontend?

  • What interests you about Rust?

  • Have you tried using Rust before? If so, what is your experience level?

  • What are you hoping to get out of this course?

Objective

To help people in the SF Bay Area learn Rust, a fantastic programming language that is rising in popularity both on the desktop and blockchain (via Solana, Cosmos, Polkadot, Elrond and others). It’s consistently been the #1 Most Loved Language on Stack Overflow because it’s so fun to use.

We will focus primarily on core Rust programming on desktop computing. Rust has its own idiosyncrasies that make it different from any other language. All material covered applies equally to backend development, web frontend (via WASM), blockchain, games, desktop GUIs, any program you want to build!

This course is intended for programmers who’re already comfortable with one or more language. Years of experience shouldn’t stop someone from taking this course if they’re interested, but a general estimate would be 1 year of experience ranging up to 20+ years of experience, including self-taught hobbyists, bootcamp grads, Computer Science grads and professional software engineers.

By the end of the 6 weeks, participants will be able to produce working, compiling Rust code. They’ll understand how to use Rust-specific features like algebraic datatypes, traits, iterators, the different String and collection types, and have practice in working with the borrow checker β€” figuring out how to solve errors, and harnessing its power to write safe and fast code. Participants who’re coming from a non-systems language background will learn about memory management and the stack vs. the heap.

Meeting Format

  • Meet once a week

  • 25 minute lecture followed by in-class project time where you can get help from the instructors or other students

  • Project designed to be completed during the class with extra credit component for take-home (or if you finish early)

  • We leave 2 hours for project time, people can leave early of course

  • Discord server for communicating throughout the week, announcements, getting help, sharing things people are doing, general conversation

Curriculum

Curriculum is posted on GitHub README so people in course can follow along and get all the text/links. We could potentially post videos on YouTube as well.

Week 0: Installation

Before starting the course, you should get Rust installed via rustup, and IDE support up and running.

Install Rust

Installation instructions for Mac/Windows/Linux (detects your operating system): https://www.rust-lang.org/tools/install

IDE Setup

Both IntelliJ Rust and rust-analyzer offer top-tier IDE support for Rust. For this course, we insist you install the language plugins. They will help you greatly as you’re learning the language, the autocomplete suggestions will help you learn the APIs and syntax, and the hints will help you fix compiler issues and teach you how to write idiomatic Rust code.

  • For IntelliJ: Install any JetBrains editor, and search for rust in the plugins marketplace.

  • For VSCode: Search for rust-analyzer in the plugins marketplace. The author is matklad. Do NOT install the β€œRust” plugin – that has basically been deprecated for the past several years.

  • For other editors (Vim/Emacs/Sublime/Atom/Kakuone/etc.), see https://rust-analyzer.github.io/

In rust-analyzer or IntelliJ Rust settings: - Turn on auto-rustfmt on save - Enable the clippy linter - Helps you write idiomatic Rust code and catches mistakes. Clippy literally teaches you Rust by detecting unidiomatic code, offering suggestions, and even linking to tutorials

Week 1: Introduction, Cargo, Integer types, error handling with Result and Option types

People should try to have Rust and either IntelliJ Rust or rust-analyzer working on their machines BEFORE class. β€œHello, World!” should be up and running with cargo run.

  • Growing popularity of Rust

    • Originally developed at Mozilla to use in certain parts of Firefox

    • These days it consistently wins the #1 Most Loved Language on StackOverflow

    • Versatile, can be used for frontend (WASM) or backend web code, for making games, for making operating systems, and programs are β€œlow-level” and can take full advantage of the machine and CPU.

    • One of the popular blockchains, Solana, is big on writing smart contacts in Rust – to attract developers. People love using Rust

  • What will you get out of using Rust?

    • It’s a fun language to use

    • Top-tier IDE support (IntelliJ Rust for JetBrains and rust-analyzer for every other editor)

    • If you’re not a low-level programmer, you will learn about low-level.

    • Has cutting-edge type system inspired by Haskell. Your code β€œclicks” together:

      • C++/Java: Rust type system encodes null/errors (exceptions)

      • TypeScript: TypeScript is unsound. If you think the types in TypeScript save you from making mistakes, well you basically β€œain’t seen nothin’ yet”

      • Kotlin/Swift/Scala: Familiar, use of Option and Result types

  • Borrow checker:

    • Prevents safety and security issues that’re footguns in C/C++.

    • Enables β€œFeArLeSS CoNCURReNcy” – can ensure that more than one thread isn’t mutating the same data. To my knowledge, no other language can do this.

      • rayon: Rust library to β€œsprinkle some concurrency on it”. Basically you add .par_iter() to your code and it’s automatically concurrent

  • Integer sizes, signed and unsigned

  • Error handling

  • Start of project. cargo new and choose β€œbin”. Entrypoint for program is fn main() as shown in β€œHello, World!” example.

  • play.rust-lang.org

  • println! macro

  • How to define a function

  • Semicolons and returning unit or other types, don’t use return unless it’s an early return

  • Can’t mix integer types

  • Type inference

  • Explain what is usize (The integer type of your machine)

  • Introduce the borrow checker with fn my_print(s: String) {} example.

  • Link to borrow checker videos from intorust.com

Projects:

  • Factorial

  • Fibonacci

  • Fac and Fib working with large numbers (u128)

  • Mention of BigInt/BigUint for infinite precision numbers like in Python/Ruby/JS/etc.

  • Read file containing numbers (separated by newlines), add all numbers together.

  • Take home project: Guessing game (also in the Rust book)

Week 2: Sum types (structs and enums) and pattern matching, the ? operator for error handling

  • Review from previous week: look at other people’s projects and answer questions

  • Show definitions of Option/Result, they’re just enums

  • Show how to handle errors using the match statement

  • Show how structs and enums can be used for data modeling

  • if let vs match vs monadal style for Option/Result

Week 3: More into the borrow checker

  • Review from previous week: look at other people’s projects and answer questions

  • C example of use after free

  • 'static and lifetimes. Structs containing references must declare a lifetime, they’re otherwise 'static. A regular struct without a lifetime, is, in a way, static.

  • Auto-deref

  • Copy and Clone

Week 4: Vec, HashMaps, arrays, slices, iterators (and closures)

Week 5: Traits and Box, From/Into, Defining methods on structs

Week 6: Global variables and multithreading, other smart pointers

  • const and lazy_static

  • Multithreading via both thread::spawn and rayon

  • Mutex

Last updated