Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PartialEq implementations for Option and Result are painfully restrictive #55452

Closed
spacejam opened this issue Oct 28, 2018 · 2 comments
Closed
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@spacejam
Copy link

current implementation:

impl<T> PartialEq<Option<T>> for Option<T> where
    T: PartialEq<T>

impl<T, E> PartialEq<Result<T, E>> for Result<T, E> where
    E: PartialEq<E>,
    T: PartialEq<T>, 

desired implementation:

impl<A, B> PartialEq<Option<B>> for Option<A> where 
    A: PartialEq<B>

impl<TA, TB, EA, EB> PartialEq<Result<TB, EB>> for Result<TA, EA> where
    EA: PartialEq<EB>,
    TA: PartialEq<TB>, 

This would allow nested types that can be compared to be compared without mapping over the structure. I have a particularly painful usecase in sled, where I return a special zero-copy read pointer for some operations that allows me to avoid clones of requested buffers without using an Arc. This pointer type implements PartialEq<T> where T: AsRef<[u8]> so it can be compared against vectors, slices, etc... But the database returns responses to requests as something like Result<Option<ZeroCopyPointer>> which really makes it cumbersome to do things like assert!(Ok(Some(zcp)) == Ok(Some(vec![1,2,3,4]))).

I see a little discussion of something similar at #20927, but it's not totally clear to me based on that if this change would be out of the question due to possible backwards-compatibility concerns.

Is there a major reason why this is impossible with today's rust? I'm happy to implement it if not.

@memoryruins memoryruins added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Oct 29, 2018
@varkor
Copy link
Member

varkor commented Oct 29, 2018

This is covered by #20063. See #20063 (comment) in particular.

@varkor varkor closed this as completed Oct 29, 2018
@spacejam
Copy link
Author

@varkor thanks for the info! Hoping this will be feasible one day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

3 participants