@@ -66,7 +66,7 @@ parameter itself but rather a type that includes the type parameter.
66
66
67
67
#### Partially generic types
68
68
69
- One situation where this is occurs is when you want to write functions
69
+ One situation where this occurs is when you want to write functions
70
70
where types are partially known and have those interact with other
71
71
functions that are fully generic. To explain the situation, let's
72
72
examine some code adapted from rustc.
83
83
Now, imagine I want to write some code that operates over all keys
84
84
whose value is an ` Option<T> ` for some ` T ` :
85
85
86
- fn example<T,K:Key<Option<T>>(table: &Table<Option<T>, K>) { ... }
86
+ fn example<T,K:Key<Option<T>>> (table: &Table<Option<T>, K>) { ... }
87
87
88
88
This seems reasonable, but this code will not compile. The problem is
89
89
that the compiler needs to know that the value type implements
@@ -98,7 +98,7 @@ There are workarounds. I might write a new trait `OptionalValue`:
98
98
99
99
and then I could write my example as:
100
100
101
- fn example<T,O:OptionalValue<T>,K:Key<O>(table: &Table<O, K>) { ... }
101
+ fn example<T,O:OptionalValue<T>,K:Key<O>> (table: &Table<O, K>) { ... }
102
102
103
103
But this is making my example function, already a bit complicated,
104
104
become quite obscure.
0 commit comments