doc.rust-lang.org
The Rust Programming Language by Steve Klabnik, Carol Nichols, and Chris Krycho, with contributions from the Rust Community This version of the text assumes you’re using Rust 1.90.0 (released 2025-09-18) or later with edition = "2024" in th...
The Rust Programming Language
Book
2024-02-01
~1 min read
doc.rust-lang.org
Foreword The Rust programming language has come a long way in a few short years, from its creation and incubation by a small and nascent community of enthusiasts, to becoming one of the most loved and in-demand programming languages in the...
The Rust Programming Language
Book
2024-02-01
~2 min read
doc.rust-lang.org
Introduction Note: This edition of the book is the same as The Rust Programming Language available in print and ebook format from No Starch Press. Welcome to The Rust Programming Language, an introductory book about Rust. The Rust programmi...
The Rust Programming Language
Book
2024-02-01
~7 min read
doc.rust-lang.org
Getting Started Let’s start your Rust journey! There’s a lot to learn, but every journey starts somewhere. In this chapter, we’ll discuss: • Installing Rust on Linux, macOS, and Windows • Writing a program that prints Hello, world! • Using...
The Rust Programming Language
Book
2024-02-01
~1 min read
doc.rust-lang.org
Installation The first step is to install Rust. We’ll download Rust through rustup, a command line tool for managing Rust versions and associated tools. You’ll need an internet connection for the download. Note: If you prefer not to use rus...
The Rust Programming Language
Book
2024-02-01
~4 min read
doc.rust-lang.org
Hello, World! Now that you’ve installed Rust, it’s time to write your first Rust program. It’s traditional when learning a new language to write a little program that prints the text Hello, world! to the screen, so we’ll do the same here! N...
The Rust Programming Language
Book
2024-02-01
~5 min read
doc.rust-lang.org
Hello, Cargo! Cargo is Rust’s build system and package manager. Most Rustaceans use this tool to manage their Rust projects because Cargo handles a lot of tasks for you, such as building your code, downloading the libraries your code depend...
The Rust Programming Language
Book
2024-02-01
~8 min read
doc.rust-lang.org
Programming a Guessing Game Let’s jump into Rust by working through a hands-on project together! This chapter introduces you to a few common Rust concepts by showing you how to use them in a real program. You’ll learn about let, match, meth...
The Rust Programming Language
Book
2024-02-01
~27 min read
doc.rust-lang.org
Common Programming Concepts This chapter covers concepts that appear in almost every programming language and how they work in Rust. Many programming languages have much in common at their core. None of the concepts presented in this chapte...
The Rust Programming Language
Book
2024-02-01
~1 min read
doc.rust-lang.org
Variables and Mutability As mentioned in the “Storing Values with Variables” section, by default, variables are immutable. This is one of many nudges Rust gives you to write your code in a way that takes advantage of the safety and easy con...
The Rust Programming Language
Book
2024-02-01
~6 min read
doc.rust-lang.org
Data Types Every value in Rust is of a certain data type, which tells Rust what kind of data is being specified so that it knows how to work with that data. We’ll look at two data type subsets: scalar and compound. Keep in mind that Rust is...
The Rust Programming Language
Book
2024-02-01
~12 min read
doc.rust-lang.org
Functions Functions are prevalent in Rust code. You’ve already seen one of the most important functions in the language: the main function, which is the entry point of many programs. You’ve also seen the fn keyword, which allows you to decl...
The Rust Programming Language
Book
2024-02-01
~6 min read
doc.rust-lang.org
Comments All programmers strive to make their code easy to understand, but sometimes extra explanation is warranted. In these cases, programmers leave comments in their source code that the compiler will ignore but that people reading the s...
The Rust Programming Language
Book
2024-02-01
~1 min read
doc.rust-lang.org
Control Flow The ability to run some code depending on whether a condition is true and the ability to run some code repeatedly while a condition is true are basic building blocks in most programming languages. The most common constructs tha...
The Rust Programming Language
Book
2024-02-01
~11 min read
doc.rust-lang.org
Understanding Ownership Ownership is Rust’s most unique feature and has deep implications for the rest of the language. It enables Rust to make memory safety guarantees without needing a garbage collector, so it’s important to understand ho...
The Rust Programming Language
Book
2024-02-01
~1 min read
doc.rust-lang.org
What Is Ownership? Ownership is a set of rules that govern how a Rust program manages memory. All programs have to manage the way they use a computer’s memory while running. Some languages have garbage collection that regularly looks for no...
The Rust Programming Language
Book
2024-02-01
~18 min read
doc.rust-lang.org
References and Borrowing The issue with the tuple code in Listing 4-5 is that we have to return the String to the calling function so that we can still use the String after the call to calculate_length, because the String was moved into cal...
The Rust Programming Language
Book
2024-02-01
~6 min read
doc.rust-lang.org
The Slice Type Slices let you reference a contiguous sequence of elements in a collection. A slice is a kind of reference, so it does not have ownership. Here’s a small programming problem: Write a function that takes a string of words sepa...
The Rust Programming Language
Book
2024-02-01
~9 min read
doc.rust-lang.org
Using Structs to Structure Related Data A struct, or structure, is a custom data type that lets you package together and name multiple related values that make up a meaningful group. If you’re familiar with an object-oriented language, a st...
The Rust Programming Language
Book
2024-02-01
~1 min read
doc.rust-lang.org
Defining and Instantiating Structs Structs are similar to tuples, discussed in “The Tuple Type” section, in that both hold multiple related values. Like tuples, the pieces of a struct can be different types. Unlike with tuples, in a struct...
The Rust Programming Language
Book
2024-02-01
~8 min read