Skip to content

Misleading example for bitflag_match! #452

@NectoT

Description

@NectoT

In the example, Flags::A | Flags::B pattern is used to print "A and/or B are set", but that pattern does not actually do that. It only matches A and B. The following code, which is a slightly modified code from the example itself, panics when trying to match Flags::A

use bitflags::{bitflags, bitflags_match};

bitflags! {
    #[derive(PartialEq)]
    struct Flags: u8 {
        const A = 1 << 0;
        const B = 1 << 1;
        const C = 1 << 2;
    }
}

let flags = Flags::A; // Flags::A | Flags::B in the example

bitflags_match!(flags, {
    Flags::A | Flags::B => println!("A and/or B are set"),
    _ => panic!("neither A nor B are set"), // println in the example
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions