October 2018
Beginner
180 pages
4h 48m
English
If we want to have functions that are part of a type with generic type parameters, we need to have an implementation block, the same as if the type didn't have those parameters, but we need to parameterize the implementation block, too.
Here is the beginning of our implementation block for the TreeNode type:
impl<K, V> TreeNode<K, V> where K: PartialOrd + PartialEq {
Now, TreeNode<K, V> is the data type we're implementing functionality for. It's the impl<K, V> part that tells the compiler that K and V are generic type parameters, and it's K: PartialOrd + PartialEq that tells it the trait bounds for those parameters. It does not just use the same generic type parameters and ...
Read now
Unlock full access