Skip to content

BitFlags should implement PartialEq with #[derive] to allow for matching on constants of BitFlags type #60

@pamburus

Description

@pamburus

Constants of type BitFlags cannot be used as a pattern in match expressions because it has manually implemented PartialEq trait.
To be able to use constants of a type in match expressions, the type must derive PartialEq trait.

Here is the exact error message:

to use a constant of type `BitFlags<MyFlag, u16>` in a pattern, `BitFlags<MyFlag, u16>` must be annotated with `#[derive(PartialEq)]`
the traits must be derived, manual `impl`s are not sufficient
see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details

But it looks like there is no need in manual implementation of PartialEq trait.
It anyway just compares the inner values

impl<T, N: PartialEq> PartialEq for BitFlags<T, N> {
    #[inline(always)]
    fn eq(&self, other: &Self) -> bool {
        self.val == other.val
    }
}

Please consider deriving PartialEq.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions