Code Monkey home page Code Monkey logo

Comments (7)

Dushistov avatar Dushistov commented on May 25, 2024 3

May be generate const array or const function that return array that contains
all values?

Then implementation of iteration will be strait forward,
plus the array may also contains names:

const fn all_values_names() -> [(Flag, &'static str); N]

This helps in implementation of custom serialization/deserialization (#147) or custom debug (#168).

What do you think?

Example of possible use-case: I want parse / generate strings like: "ab bc cd" <-> Flags::AB | Flags::BC | Flags::CD,

to generate string I need iteration plus names of constants in lower-case,
to deserialize I need names in lower-case

from bitflags.

alexcrichton avatar alexcrichton commented on May 25, 2024 2

Seems plausible!

from bitflags.

RReverser avatar RReverser commented on May 25, 2024

@alexcrichton Is this something that would be accepted in the library?

from bitflags.

djg avatar djg commented on May 25, 2024

I was just thinking about implementing this feature for some code I'm working on, if it's not already implemented.

from bitflags.

sam0x17 avatar sam0x17 commented on May 25, 2024

Would love this

from bitflags.

KodrAus avatar KodrAus commented on May 25, 2024

In #278 we merged an implementation that allows iterating over flags and their names. It effectively looks like:

pub fn iter(self) -> impl Iterator<Item = (&'static str, Self)>

It effectively does what @Dushistov described, but internally. There's still design work to be done on this though, IntoIterator to implement, and some refactoring of how we generate flags types so we can make that iter function return a concrete type instead of impl Trait so I'll keep this ticket open for now to consider those.

from bitflags.

KodrAus avatar KodrAus commented on May 25, 2024

This is now implemented in 2.0.0-rc.1

from bitflags.

Related Issues (20)

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.