Function Signature

In Rust github issues/62358, I found someone suggest to implement the following method

    pub fn contains(&self, x: &T) -> bool where T: PartialEq {
        match self {
            Some(y) => y == x,
            None => false,
        }
    }

    pub fn contains(&self, x: &T) -> bool where T: PartialEq {
        match self {
            Ok(y) => y == x,
            Err(_) => false,
        }
    }

but the member of the language suggest

Should we update the signatures to fn contains<U>(&self, x: &U) -> bool where T: PartialEq<U> ?

Can any one explain me what is the different between those two function signatures?

With regards.

For the first one, x must be a reference to a T and that T must implement PartialEq with itself, that T must be the same type as the T of the container. In the second one, the type U can be different from the type T of the container, but T must implement PartialEq with that U.

Since U could be T, the second the solution is more general.

5 Likes

Thank a lot bro.