3 Compound data types
This chapter covers
- Composing data with structs
- Creating enumerated data types
- Adding methods and handling errors in a type-safe manner
- Defining and implementing common behavior with traits
- Understanding how to keep implementation details private
- Using cargo to build documentation for your project
Welcome to chapter 3. If we spent the last chapter looking at Rust’s atoms, this chapter is focused more on its molecules.
This chapter focuses on two key building blocks for Rust programmers, struct
and enum
. Both are forms of compound data types. Together, struct
and enum
can compose other types to create something more useful than what those other types would be alone. Consider how a 2D point (x,y) is composed from two numbers, ...
Get Rust in Action 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.