Skip to content

Is there a more ergonomic way of accepting either a Bitflags<MyEnum> or just MyEnum? #29

Closed
@joseluis

Description

@joseluis

I have a structure that accepts Bitflags for a flags field. And it works beautifully well except in the case of wanting to use just one flag:

// OK
let a = MyStruct::new(MyEnum::Flag1 | MyEnum::Flag2);

// Fails
let b = MyStruct::new(MyEnum::Flag1);
                   // ^^^^^^^^^^^^^ expected struct `enumflags2::BitFlags`, found enum `mycrate::MyEnum`

// the ugly solution 
let b = MyStruct::new(enumflags2::BitFlags::from(MyEnum::Flag1));

Do you happen know of a more ergonomic way for the user to provide just one flag? Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions