Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Generics, Trait Bounds, and Lifetimes

If Chapter 3 was about building high-level abstractions for humans to understand, and Chapter 4 about imposing restrictions in step with modern computer hardware to achieve efficiency, then this chapter extends and combines the two. On the abstraction side, we introduce types that can take types as parameters — generics. Then we’ll learn about traits, which can constrain generics. Finally we’ll come to see that lifetimes not only deliver the performance of a low-level language, but also integrate perfectly with the type system, as in a high-level one.