Skip to Content
Rust in Action
book

Rust in Action

by Tim McNamara
August 2021
Beginner to intermediate
456 pages
12h 24m
English
Manning Publications
Content preview from Rust in Action

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, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust in Action

Rust in Action

Tim McNamara
Effective Rust

Effective Rust

David Drysdale
Command-Line Rust

Command-Line Rust

Ken Youens-Clark

Publisher Resources

ISBN: 9781617294556Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentErrata PagePurchase Link