Skip to content

Is it possible to implement PartialEq-like traits with #[recursive]? #2

@TheVeryDarkness

Description

@TheVeryDarkness

Hello! Thanks for your great work! I've used this in several scenarios, but I have a trait Equiv, which compares enums by each variant. It's like below:

trait Equiv {
    fn equiv(&self, other: &Self) -> bool;
}

Given an enum with the most common usage of derive_recursive below:

#[derive(Recursive)]
#[recursive(
    impl<T: Equiv, U: Equiv> Equiv for Self<T, U> {
        fn equiv(&self, other: &Self) -> bool { aggregate = && }
    }
)]
enum Either<T, U> {
    Left(T),
    Right(U),
}

It will be compiled to:

impl<T: Equiv, U: Equiv> Equiv for Either<T, U> {
    fn equiv(&self, arg0: &Self) -> bool {
        match self {
            Self::Left(f0) => <T as Equiv>::equiv(f0, arg0),
            Self::Right(f0) => <U as Equiv>::equiv(f0, arg0),
        }
    }
}

However, <T as Equiv>::equiv accepts 2 arguments of &T, but not 1 argument of &T and 1 argument of &Either<T, U>.

Is there a way to implement this trait correctly in current version?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions