13 Box and Rust documentation

 

This chapter covers

  • Reading Rust documentation
  • Attributes, which are small bits of extra information
  • Box, a smart pointer that gives a lot of extra flexibility

This chapter is a bit of a break after the last two, with Box being the only really new concept. But Box is one of the most important types in Rust because it makes a lot of things possible that otherwise wouldn’t be, especially when working with traits. You’ll be glad to know it! To start off the chapter, though, we will relax a bit and learn how to read documentation, which in Rust is always generated in the same way. This is nice because once you get used to reading documentation in Rust, you will be able to understand the documentation for anyone else’s code. We’ll also learn about attributes, which are the small pieces of code that start with a # that you see above a type (like #[derive(Debug)], for example) or at the beginning of a file.

13.1 Reading Rust documentation

13.1.1 assert_eq!

13.1.2 Searching

13.1.3 The [src] button

13.1.4 Information on traits

13.1.5 Attributes

13.2 Box

13.2.1 Some Box basics

13.2.2 Putting a Box around traits

13.2.3 Using a Box to handle multiple error types

13.2.4 Downcasting to a concrete type

Summary