Impl trait for subset of types


basically i have this problem:

Obviously, the way to solve it is just to write out Foo for every type. But im still struggling to understand why these restrictions are imposed on me, let the compiler blow when we actually have a conflicting implementation.?!
Secondly, what other solutions do i have ? i can think of creating some sort of "tag" - trait which i can put on my primitive implementations so that it does not match other trait bounds. But that gets messy quite quickly

Is there a way to specify negative trait bounds ? e.g. impl<T: !Bar> Foo for T

thanks a lot guys!

This restriction exists because if it didn't, then it would be a breaking change for the standard library to add a new implementation of Deref<Target=&'static str> for f64. It's not possible to use negative trait bounds or another trick to get around it.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.