Here is a toy example to reproduce my problem.
I want to create a different impl of Splash according to whether a Puddle is Clear or Muddy.
The compiler tells me that my Muddy Splash and Clear Splash conflict.
However there is no way I can find (so far) to specify a type P that implements Puddle with both Puddle::Purity=Muddy and Puddle::Purity=Clear. The ExamplePuddle also fails to compile with conflicting impls of Puddle.
So if I can't implement multiple different Puddle::Purity for any type P, then why can't I implement different Splash for different Puddle::Purity constraints?
trait WaterPurity {}
struct Muddy;
impl WaterPurity for Muddy {}
struct Clear;
impl WaterPurity for Clear {}
trait Puddle {
type Purity: WaterPurity;
}
trait Splash {}
struct Foot;
// Conflicting implementations of Splash for type (_, Foot)
impl<P> Splash for (P, Foot) where
P: Puddle<Purity=Muddy> {}
impl<P> Splash for (P, Foot) where
P: Puddle<Purity=Clear> {}
struct ExamplePuddle;
// Conflicting implementations of trait Puddle for ExamplePuddle
impl Puddle for ExamplePuddle {
type Purity = Muddy;
}
impl Puddle for ExamplePuddle {
type Purity = Clear;
}
Splash` constrained by `Puddle::Purity` should not be considered conflicting. I don't care about writing the multiple Puddle impls, I want multiple Splashes, but the compiler error for the multiple Splashes implies the multiple Puddles would be possible when clearly it is not.
– World Outsider Oct 13 '21 at 13:26