O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generic types

Imagine a situation where you need to encapsulate some values inside something else. Vectors, HashMaps, Ropes, all sorts of trees, and graphs... the amount of possible useful data structures is endless, and so is the amount of possible types of values you might want to put in them. Furthermore, a useful programming technique is to encapsulate your types inside others to enhance their semantic value, which may at best increase the clarity and safety of your code.

Now, imagine that you need to implement a method for such a type, such as fetching a specific key from a HashMap. HashMaps have keys, which point to values. Naively, you would need to write a specific method for each key-value type pair that you need in your program, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required