Chapter 3. Concepts
The first two chapters of this book covered Rust’s types and traits, which helps provide the vocabulary needed to work with some of the concepts involved in writing Rust code—the subject of this chapter.
The borrow checker and lifetime checks are central to what makes Rust unique; they are also a common stumbling block for newcomers to Rust and so are the focus of the first two Items in this chapter.
The other Items in this chapter cover concepts that are easier to grasp but are nevertheless a bit different from writing code in other languages. This includes the following:
-
Advice on Rust’s
unsafe
mode and how to avoid it (Item 16) -
Good news and bad news about writing multithreaded code in Rust (Item 17)
-
Advice on avoiding runtime aborts (Item 18)
-
Information about Rust’s approach to reflection (Item 19)
-
Advice on balancing optimization against maintainability (Item 20)
It’s a good idea to try to align your code with the consequences of these concepts. It’s possible to re-create (some of) the behavior of C/C++ in Rust, but why bother to use Rust if you do?
Item 14: Understand lifetimes
This Item describes Rust’s lifetimes, which are a more precise formulation of a concept that existed in previous compiled languages like C and C++—in practice if not in theory. Lifetimes are a required input for the borrow checker described in Item 15; taken together, these features form the heart of Rust’s memory safety guarantees.
Introduction to the Stack
Lifetimes ...
Get Effective Rust now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.