1
pub trait HumanLike{
    fn full_name(&self) -> String;
}
impl<T> PartialEq for T where T: HumanLike {
    fn eq(&self, other: &Self) -> bool {
        self.full_name() == other.full_name()
    } 
}

It gave me this error. I don't know what to do.

 = note: conflicting implementation in crate `core`:
           - impl<A, B> PartialEq<&B> for &A
             where A: PartialEq<B>, A: ?Sized, B: ?Sized;
   = note: downstream crates may implement trait `HumanLike` for type `&_`

I really want to do this

(any Humanlike struct) == (any Humanlike struct)
  • This isn't possible because you don't own the generic trait `PartialEq`. The linked questions have some alternative suggestions. – trent Feb 12 '21 at 14:12
  • Maybe also [Implement a trait for all types implementing a trait](https://stackoverflow.com/q/57274864/3650362) and [How to test for equality between trait objects?](https://stackoverflow.com/q/25339603/3650362) could help. – trent Feb 12 '21 at 14:14
  • Thanks, I don't like all those solutions, workarounds. Guess this answer to this specific question is no. I know the alternatives. Like: 1. impl on struct. 2. use a custum trait, and just do Humanlike.equal(Humanlike). etc. – Alexander Crescent Feb 12 '21 at 14:22

0 Answers0