It’s now time to learn about Rust’s third generic type (const generics) and all the other things to do with const and static in Rust. Const generics let you be generic over const values, which is most useful when working with arrays. Const functions are similar to regular functions, but they can be called at compile time before your program starts. We will also start to learn about the unsafe side of Rust, starting with static mut, a static that is unsafe to use. We’ll also learn about why unsafe Rust even exists and why you might never even need to touch it. Then we will start moving into external crates, which, thanks to Cargo, are extremely easy to use.
- Generic over types—These are the generics we are most familiar with, as we learned them back in chapter 5. A generic T: Debug means any type that implements the Debug trait. When Rust users say generics, they are usually talking about type generics.
- Generic over lifetimes—Lifetimes are actually another sort of generics. For example, when you have a 'static lifetime in a function, it means any type that has a 'static lifetime. We began learning about lifetimes in chapter 10.