Wrong trait chosen based on type parameter

hel*_*low 3 rust

I have a binary trait Resolve.

pub trait Resolve<RHS = Self> {
    type Output;
    fn resolve(self, rhs: RHS) -> Self::Output;
}
Run Code Online (Sandbox Code Playgroud)

I implemented the trait for something trivial where both arguments are taken by reference (self is &'a Foo and rhs is &'b Foo):

struct Foo;

impl <'a, 'b> Resolve<&'b Foo> for &'a Foo {
    type Output = Foo;
    fn resolve(self, rhs: &'b Foo) -> Self::Output {
        unimplemented!()
    }
}
Run Code Online (Sandbox Code Playgroud)

If I now write

fn main() {
    let a: &Foo = &Foo;
    let b = Foo;
    a.resolve(&b);
}
Run Code Online (Sandbox Code Playgroud)

it will compile just fine, but if I try to implement it on my struct Signal, it will not work.

pub struct Signal<'a, T> {
    ps: Vec<&'a T>,
}

impl<'a, T: Resolve<&'a T, Output = T> + 'a> Signal<'a, T> {
    pub fn foo(&mut self) {
        let a: &T = &self.ps[0];
        let b = &self.ps[1];
        a.resolve(b);
    }
}
Run Code Online (Sandbox Code Playgroud)
pub trait Resolve<RHS = Self> {
    type Output;
    fn resolve(self, rhs: RHS) -> Self::Output;
}
Run Code Online (Sandbox Code Playgroud)

How do I get this example working? (playground)

tre*_*tcl 6

绑定的特征foo仅表示T实现Resolve,但您尝试调用.resolve()type的值&T

如果说,取而代之的是,引用T必须实现Resolve,你需要一个更高的排名特质约束

impl<'a, T> Signal<'a, T>
where
    for<'b> &'b T: Resolve<&'a T, Output = T>,
{
    pub fn foo(&mut self) { ... }
}
Run Code Online (Sandbox Code Playgroud)