## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# Foreword

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Introduction

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Getting Started

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Installation

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Hello, World!

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Hello, Cargo!

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Programming a Guessing Game

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Common Programming Concepts

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Variables and Mutability

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Data Types

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# How Functions Work

## Functions

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Comments

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Control Flow

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Understanding Ownership

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# What is Ownership?

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# References & Borrowing

## References and Borrowing

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Slices

## The Slice Type

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Using Structs to Structure Related Data

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Defining and Instantiating Structs

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# An Example Program Using Structs

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Method Syntax

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Enums and Pattern Matching

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Defining an Enum

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# The match Control Flow Operator

## The `match` Control Flow Operator

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Concise Control Flow with if let

## Concise Control Flow with `if let`

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Using Modules to Reuse and Organize Code

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# mod and the Filesystem

## `mod` and the Filesystem

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Controlling Visibility with pub

## Controlling Visibility with `pub`

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Referring to Names in Different Modules

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Common Collections

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Vectors

## Storing Lists of Values with Vectors

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Strings

## Storing UTF-8 Encoded Text with Strings

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Hash Maps

## Storing Keys with Associated Values in Hash Maps

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Error Handling

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Unrecoverable Errors with panic!

## Unrecoverable Errors with `panic!`

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Recoverable Errors with Result

## Recoverable Errors with `Result`

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# To panic! or Not to panic!

## To `panic!` or Not to `panic!`

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Generic Types, Traits, and Lifetimes

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Generic Data Types

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Traits: Defining Shared Behavior

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Validating References with Lifetimes

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Writing Automated Tests

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Writing tests

## How to Write Tests

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Running tests

## Controlling How Tests Are Run

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Test Organization

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# An I/O Project: Building a Command Line Program

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Accepting Command Line Arguments

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Reading a File

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Refactoring to Improve Modularity and Error Handling

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Developing the Library’s Functionality with Test Driven Development

## Developing the Library’s Functionality with Test-Driven Development

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Working with Environment Variables

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Writing Error Messages to Standard Error Instead of Standard Output

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Functional Language Features: Iterators and Closures

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Closures: Anonymous Functions that Can Capture Their Environment

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Processing a Series of Items with Iterators

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Improving Our I/O Project

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Comparing Performance: Loops vs. Iterators

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# More About Cargo and Crates.io

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Customizing Builds with Release Profiles

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Publishing a Crate to Crates.io

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Cargo Workspaces

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Installing Binaries from Crates.io with cargo install

## Installing Binaries from Crates.io with `cargo install`

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Extending Cargo with Custom Commands

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Smart Pointers

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

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

## Using `Box<T>` to Point to Data on the Heap

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# The Deref Trait Allows Access to the Data Through a Reference

## Treating Smart Pointers Like Regular References with the `Deref` Trait

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# The Drop Trait Runs Code on Cleanup

## Running Code on Cleanup with the `Drop` Trait

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Rc<T>, the Reference Counted Smart Pointer

## `Rc<T>`, the Reference Counted Smart Pointer

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# RefCell<T> and the Interior Mutability Pattern

## `RefCell<T>` and the Interior Mutability Pattern

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Creating Reference Cycles and Leaking Memory is Safe

## Reference Cycles Can Leak Memory

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Fearless Concurrency

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Threads

## Using Threads to Run Code Simultaneously

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Message Passing

## Using Message Passing to Transfer Data Between Threads

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Shared State

## Shared-State Concurrency

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Extensible Concurrency: Sync and Send

## Extensible Concurrency with the `Sync` and `Send` Traits

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Object Oriented Programming Features of Rust

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Characteristics of Object-Oriented Languages

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Using Trait Objects that Allow for Values of Different Types

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Implementing an Object-Oriented Design Pattern

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Patterns and Matching

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# All the Places Patterns May be Used

## All the Places Patterns Can Be Used

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Refutability: Whether a Pattern Might Fail to Match

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# All the Pattern Syntax

## Pattern Syntax

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Advanced Features

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Unsafe Rust

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Advanced Lifetimes

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Advanced Traits

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Advanced Types

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Advanced Functions & Closures

## Advanced Functions and Closures

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Final Project: Building a Multithreaded Web Server

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# A Single Threaded Web Server

## Building a Single-Threaded Web Server

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Turning our Single Threaded Server into a Multithreaded Server

## Turning Our Single-Threaded Server into a Multithreaded Server

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Graceful Shutdown and Cleanup

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Appendix

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# A - Keywords

## Appendix A: Keywords

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# B - Operators and Symbols

## Appendix B: Operators and Symbols

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# C - Derivable Traits

## Appendix C: Derivable Traits

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# D - Macros

## Appendix D: Macros

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# E - Translations

## Appendix E: Translations of the Book

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Appendix F - Newest Features

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.

# Appendix G - How Rust is Made and “Nightly Rust”

The second edition of the book is no longer distributed with Rust’s documentation.

If you came here via a link or web search, you may want to check out the current version of the book instead.

If you have an internet connection, you can find a copy distributed with Rust 1.30.