2 Basic building blocks
This chapter covers
- Exploring the core Rust idioms and patterns
- Diving into Rust generics
- Exploring traits
- Combining generics and traits
- Deriving traits automatically
In this chapter, we’ll introduce and discuss some of the most important abstractions and features in Rust. Nearly all design patterns will build atop of these core building blocks, thus it’s necessary to review them before diving deeper into other patterns. For some readers, this chapter may appear on the surface to be a review of language basics; however, we’re setting up for more advanced topics, so I recommend you don’t skip this. We will begin by discussing generics and traits in Rust, leading us to more advanced topics. Traits and generics are the core building blocks for nearly any design pattern in Rust, along with Rust’s pattern matching and functional features (which we’ll discuss in the next chapter). These constitute the "meat and potatoes" of the language.