error[E0308]: mismatched types
--> src/error.rs:439:33
|
439 | self.items.contains_key(concern)
| ^^^^^^^ expected type parameter, found associated type
|
= note: expected type `&C`
found type `&<C as std::borrow::ToOwned>::Owned`
You can use the fact that ToOwned::Owned: Borrow<Self>, meaning you can use .borrow to get the appropriate reference. This is still rather odd, as though you did explicitly mark the HashMap to use C::Owned. Anyway, here's the code.
Thank you,
both of the solutions by OptimisticPeach and prataprc work.
It still bugs me why would compiler assume that C is the key. Since the second solution differs from mine only in the "?Sized" constraint, the reason is probably to be found there.
I'll check the last solution too but it reminds me upon something I have tried and abandoned for something unrelated to this topic.
The key is always C::Owned. The problem is the compilers error message. It should be saying the found type is incompatible with the generic function bounds, then optionally make some suggestions. Still probably would only suggest to use a type &C; you may really want C::Owned: Borrow<C::Owned> which is also achieved with use as @OptimisticPeach comments.