Rust

Table of Contents

Rust Book, 2nd ed.

Notes taken from the second edition of the Rust book.

Common Programming Concepts

Variables and Mutability

Data Types

How Functions Work

Comments

Control Flow

Understanding Ownership

What is Ownership?

References and Borrowing

Slices

Structs

General

Method Syntax

Enums and Pattern Matching

Defining an Enum

The match Control Flow Operator

Concise Control Flow with if let

Modules

mod and the Filesystem

Controlling Visibility with pub

Importing Names

Common Collections

General Notes

Vectors

Strings

Hash Maps

Error Handling

Unrecoverable Errors with panic!

Recoverable Errors with Result

To panic! or Not To panic!

Generic Types, Traits and Lifetimes

General

Generic Data Types

Traits: Defining Shared Behavior

Validating References with Lifetimes

Testing

How to Write Tests

Controlling How Tests are Fun

Test Organization

An I/O Project Building a Small Grep

General

Accepting Command Line Arguments

Reading a File

Refactoring to Improve Modularity and Error Handling

Testing the Library’s Functionality

Working with Environment Variable

Write to stderr Instead of stdout

Functional Language features in Rust

Closures: Anonymous Functions that can Capture their Environment

Processing a Series of Items with Iterators

Improving our I/O Project

Comparing Performance: Loops versus Iterators

More about Cargo and Crates.io

Release Profiles

Publishing a Crate to Crates.io

Cargo Workspaces

Installing Binaries from Crates.io with cargo install

Extending Cargo with Custom Commands

Smart Pointers

General

Box<T> Points to Data on the Heap and Has a Known Size

The Deref Trait Allows Access to the Data Through a Reference

The Drop Trait Runs Code on Cleanup

Rc<T>, the Reference Counted Smart Pointer

RefCell<T> and the Interior Mutability Pattern

Creating Reference Cycles and Leaking Memory is Safe

Fearless Concurrency

General

Using Threads to Run Code Simultaneously

Message Passing to Transfer Data Between Threads

Shared State Concurrency

Extensible Concurrency with the Sync and Send Traits

Is Rust an Object-Oriented Programming Language?

What Does Object-Oriented Mean?

Trait Objects for Using Values of Different Types

Object-Orienated Design Pattern Implementation

Patterns Match the Structure of Values

All the Places Patterns May be Used

Refutability: Whether a Pattern Might Fail to Match

All the Pattern Syntax

Advanced Features

Unsafe Rust

Advanced Lifetimes

Advanced Traits

Advanced Types

Advanced Functions & Closures

Final Project: Building a Multithreaded Web Server

A Single Threaded Web Server

How Slow Requests Affect Thoroughput

Designing the Thread Pool Interface

Creating the Thread Pool and Storing Threads

Sending Requests to Threads Via Channels

Graceful Shutdown and Cleanup