How it works...
Generics work very well in Rust and, other than the verbose notation, they are very handy. In fact, you will find them all over the place and, as you progress in Rust, the need for better, more generic interfaces will increase.
In Step 2, we are creating a modified dynamic array (taken from the book Hands-On Data Structures and Algorithms with Rust: https://www.packtpub.com/application-development/hands-data-structures-and-algorithms-rust) that uses a generic type. Using a generic type in code works like any other type, writing T instead of i32. However, as discussed in a previous recipe, the compiler expects certain behaviors from the T type, such as implementing Clone, which is specified in the where clause of the struct ...
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.
Read now
Unlock full access