Advanced Features
We’ve come a long way! By now, you’ve learned 99% of the things you’ll need to know when writing Rust. Before we do one more project in Chapter 20, let’s talk about a few things you may run into that last 1% of the time. Feel free to use this chapter as a reference for when you run into something unknown in the wild; the features you’ll learn to use here are useful in very specific situations. We don’t want to leave these features out, but you won’t find yourself reaching for them often.
In this chapter, we’re going to cover:
- Unsafe Rust: for when you need to opt out of some of Rust’s guarantees and make yourself responsible for upholding the guarantees instead
- Advanced Lifetimes: syntax for complex lifetime situations
- Advanced Traits: Associated Types, default type parameters, fully qualified syntax, supertraits, and the newtype pattern in relation to traits
- Advanced Types: some more about the newtype pattern, type aliases, the “never” type, and dynamically sized types
- Advanced Functions and Closures: function pointers and returning closures
It’s a panoply of Rust features with something for everyone! Let’s dive in!