Hi
I'm running into conflicting implementations of trait GetInner<Table<_>>
in the below code (playground link).
If I delete what the compiler identifies as a conflicting implementation, the compiler then tells me that I have an unexpected argument in let bridge = parent.connect_to(&child);
(because it can only connect_to
Table<Parent>
) and that I should implement the (conflicting) trait as I had it before.
I am out of my depth here. Any ideas on how to resolve this? Thanks!
use std::marker::PhantomData;
trait Named {}
trait Unit {
type Name: Named;
}
struct Table<N: Named> {
_phantom: PhantomData<N>
}
impl<N: Named> Unit for Table<N> {
type Name = N;
}
struct Bridge<L: Unit, R: Unit> {
name: (L::Name, R::Name)
}
trait GetInner<O: Unit> {
type Inner;
fn inner(&self, other: & O) -> Self::Inner;
}
trait ConnectTo<R: Unit>: Sized + Unit
where Bridge<Self, R>: GetInner<Self> + GetInner<R>
{
fn connect_to(&self, other: &R) -> Bridge<Self, R>;
}
impl<L: Named, R: Named> ConnectTo<Table<R>> for Table<L> {
fn connect_to(&self, _other: &Table<R>) -> Bridge<Self, Table<R>> {
unimplemented!()
}
}
impl<L: Named, R: Named> GetInner<Table<R>> for Bridge<Table<L>, Table<R>> {
fn inner(&self, _other: & Table<R>) -> Self::Inner {
unimplemented!()
}
}
impl<L: Named, R: Named> GetInner<Table<L>> for Bridge<Table<L>, Table<R>> {
fn inner(&self, _other: & Table<L>) -> Self::Inner {
unimplemented!()
}
}
struct Parent;
struct Child;
impl Named for Parent {}
impl Named for Child {}
struct Foo {
parent: Table<Parent>,
child: Table<Child>,
bridge: Bridge<Table<Parent>, Table<Child>>
}
impl Foo {
fn new(parent: Table<Parent>, child: Table<Child>) -> Self {
let bridge = parent.connect_to(&child);
Self {
parent,
child,
bridge
}
}
}
fn main() {
}