I'm still new to rust and I'm a bit puzzled by this tiny detail below. From what I understood so far is that ==
and eq()
are pretty much equivalent. I wonder why is dereferencing y
required for the operator version but not for the function call. I was expecting that no dereferencing should be required at all since the eq
method expects a reference to y
anyways.
use std::cmp::{Eq, PartialEq};
struct X{}
struct Y {}
impl PartialEq<Y> for X{
fn eq(&self, rhs: &Y)->bool{
true
}
}
impl PartialEq for X{
fn eq(&self, rhs: &X)->bool{
true
}
}
impl Eq for X {}
fn main() {
let x = X{};
let y = Y{};
let f1 = |y: &Y| x == *y;
let f2 = |y: &Y| x.eq(y);
}