Skip to content

More general PartialEq implementation for Option #1239

@tomjakubowski

Description

@tomjakubowski

Currently, only the case where T == U is covered. Presumably this is because of derive limitations, since this impl is indeed derived in libcore.

I believe it should be possible and correct to provide the following impl:

impl<T, U> PartialEq<Option<U>> for Option<T> where T: PartialEq<U>, U: PartialEq<T> {
    fn eq(&self, rhs: &Option<U>) -> bool {
        match (self, rhs) {
            (&Some(ref lhs), &Some(ref rhs)) if lhs == rhs => true,
            (&None, &None) => true,
            _ => false
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions