"Konflikte bei Implementierungen" -Fehler in komplexem generischem Code, wie kann das behoben werden?
Ich habeBase
Merkmal, implementierenFoo<B>
für alle Typen, die @ implementiert habBar<B>
, jetzt möchte ich spezielles implementierenFoo<B>
für alleFoobar<B>
struct, woB: Base
:
trait Base {}
trait Foo<B: Base> {}
trait Bar<B: Base> {}
struct Foobar<B: Base> { _b: B }
// delete either, compile success
impl<B: Base, T: Bar<B>> Foo<B> for T {}
impl<B: Base> Foo<B> for Foobar<B> {}
fn main()
{
}
Der Kompilierungsfehler ist:
<anon>:14:1: 14:41 error: conflicting implementations for trait `Foo` [E0119]
<anon>:14 impl<B: Base, T: Bar<B>> Foo<B> for T {}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:14:1: 14:41 help: see the detailed explanation for E0119
<anon>:15:1: 15:38 note: note conflicting implementation here
<anon>:15 impl<B: Base> Foo<B> for Foobar<B> {}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Das istSpielplat