GithubHelp home page GithubHelp logo

Multiple Bits for Flag about enumflags HOT 4 OPEN

robbym avatar robbym commented on June 17, 2024
Multiple Bits for Flag

from enumflags.

Comments (4)

MaikKlein avatar MaikKlein commented on June 17, 2024

I have thought about that problem before and I am not sure what the best approach would be. I probably could add an option to allow duplicates.

Alternatively INDICATOR_NORMAL can be put outside of the enum, maybe in a function because it is just INDICATOR_IDENTIFY | INDICATOR_MUTE

Something like

impl GeneralStatus{
    pub fn normal() -> BitFlags<GeneralStatus> {
        GeneralStatus::INDICATOR_IDENTIFY | GeneralStatus::INDICATOR_MUTE
    }
}

from enumflags.

robbym avatar robbym commented on June 17, 2024

Ideally, I would like to specify which parts of a bitfield can be orred together. In my case is doesn't make sense. INDICATOR_IDENTIFY can't be orred with an other INDICATOR_, but can with the at least 1 PORT_, and any number of (BOOT_RDM, RDM_CAPABLE, or UBEA_PRESENT).

Not sure if that sort of feature should belong in this crate though. IDK

from enumflags.

robbym avatar robbym commented on June 17, 2024

I just tried sketching out what I wanted but it turns out I'd need powerset(n) types that each implemented BirOr for each type to do this.

from enumflags.

MaikKlein avatar MaikKlein commented on June 17, 2024

Ideally, I would like to specify which parts of a bitfield can be orred together. In my case is doesn't make sense. INDICATOR_IDENTIFY can't be orred with an other INDICATOR_, but can with the at least 1 PORT_, and any number of (BOOT_RDM, RDM_CAPABLE, or UBEA_PRESENT).
Not sure if that sort of feature should belong in this crate though. IDK

Ah, I am not sure that I can easily support this use case. At least I don't see an obvious API for it. I think if I would want this to be type safe I would create another wrapper on top of it that manages the indicator bits separately.

from enumflags.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.