Question about conflicting implementations

Why do I get an error compiling these impls? (error[E0119]: conflicting implementations of trait apply::Apply<_> for type &_: )

impl<F, I, R, E> Apply<I> for F
    where
        F: Fn(I) -> Result<R, E>,
{
    type Err = E;
    type Res = R;

    fn apply(&self, input: I) -> Result<Self::Res, Self::Err> { self(input) }
}

impl<T, I> Apply<I> for &T
    where
        T: Apply<I> + ?Sized,
{
    type Err = T::Err;
    type Res = T::Res;

    fn apply(&self, input: I) -> Result<Self::Res, Self::Err> { (**self).apply(input) }
}

I know that I can get around this, for example by wrapping a type. But I wonder why these impl conflict. Is &_ not a type wrapper in itself?

What if there was a reference to something that implemented the Fn(I) -> Result<R, E> trait? Then they would overlap.

1 Like

Yes it is. Well, I have to choose which trait to implement.
Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.