I want to know how to create a generic function bound to a generic trait.
In this example I have chosen BitXor
. The declaration of std::ops::BitXor
is BitXor<RHS, Result>
.
So if we have our function:
fn e<T: BitXor>(m:T, k:T) -> T {
m ^ k
}
The compiler will complain:
error: Wrong number of type arguments: expected 2 but found 0.
So I tried:
fn e<T: BitXor<U, V>, U, V>(m:T, k:T) -> T {
m ^ k
}
But get the rather confusing error:
Mismatched types: expected `U` but found `T` (expected type parameter but found type parameter).
Any solution?