Code Monkey home page Code Monkey logo

Comments (6)

KodrAus avatar KodrAus commented on June 17, 2024 3

With #348 merged, the 2.3.0 release of bitflags will support using your own custom derives again. I've added an example that demonstrates how to do this.

from bitflags.

KodrAus avatar KodrAus commented on June 17, 2024 1

This is a bit of an unfortunate regression. There isn't really a solution to exposing a way to derive traits and add methods on that internal type that doesn't come with the risk of breakage as features are added to bitflags. In general, I don't think we'll support exposing it.

I think your best option is to implement the trait manually. It's an ergonomic hit for those cases where you can't add derive support to bitflags, but there are other strategies available to reduce boilerplate, like regular macro_rules macros, or attributes on your custom derive traits that alter code generation.

I would be open though to exploring some way to improve this story in a way that didn't also erode our ability to safely evolve the library.

from bitflags.

KodrAus avatar KodrAus commented on June 17, 2024 1

@paul-hansen Since bevy_reflect is public we can add support for it in bitflags. We need to do some additional work to support libraries that require custom derives, but have a policy for unstable dependencies in #329 that should cover bevy_reflect.

from bitflags.

paul-hansen avatar paul-hansen commented on June 17, 2024

This prevents me from upgrading a personal project to 2.0 because I want to be able to use it with bevy_reflect like so:

bitflags! {
    #[derive(Reflect, FromReflect)]
    pub struct MyEnum: u8 {

This allows being able to see the values in bevy_egui_inspector and replicating the value over the network using bevy_replicion.

My project isn't important, it's just an exercise for myself, but I thought you might want to know about this use case.

from bitflags.

KodrAus avatar KodrAus commented on June 17, 2024

Looking at bevy_reflect specifically, I might put together an external library for a start like bitflags_bevy_reflect and see if we can take better advantage of the fact that the underlying type is a flags type than the derive will.

from bitflags.

KodrAus avatar KodrAus commented on June 17, 2024

I think I've got a solution for this that lets you add custom derives without bitflags needing to be directly aware of them, and without losing all the code generation that bitflags gives you.

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.