I'm again struggling with a conflicting implementation issue.
Using the IndependentSample
trait from the rand
crate, I have the following code:
pub trait SimpleSample { ... }
impl<T> SimpleSample for T where T: IndependentSample<f64> { ... }
impl SimpleSample for u32 { ... }
The compilation error is:
error[E0119]: conflicting implementations of trait `SimpleSample` for type `u32`: 15 | impl<T> SimpleSample for T where T: IndependentSample<f64> { | - first implementation here 22 | impl SimpleSample for u32 { | ^ conflicting implementation for `u32`
My understanding is that this second impl for u32
would only conflict if u32 : IndependentSample<f64>
, which isn't the case. The docs for IndependentSample
list several implementations, and none of them are for `u32. To prove this to myself I tried writing this small test function:
fn foo<T>(t: T) where T: IndependentSample<f64> { }
foo(0u32)
and got the error:
the trait bound `u32: rand::distributions::IndependentSample<f64>` is not satisfied
So what am I missing? Why do I have a conflicting implementation?
Playground link with the full code
Thanks!