Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant operator overloading for bitflags #217

Closed
wants to merge 1 commit into from

Conversation

ldm0
Copy link

@ldm0 ldm0 commented May 7, 2020

Fixes #180 Fixes #210
After rust-lang/rust#68847, we now can overload the operator as const function. This PR added a feature "constant". And a user can write compile-pass code like this:

#![feature(const_fn)]
#![allow(incomplete_features)]
#![feature(const_trait_impl)]
use bitflags::bitflags;

bitflags! {
    struct Flags: u32 {
        const A = 0b00000001;
        const B = 0b00000010;
        const C = 0b00000100;
        const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
    }
}

const B: Flags = Flags::A | Flags::B;

fn main() {
    println!("{:?}", B);
}

@KodrAus
Copy link
Member

KodrAus commented May 11, 2021

Thanks for the PR @ldm0! It looks like things are steadily moving forwards with const trait impls, so I think we'd be best waiting for that to land in some complete form first to save us too much infrastructure to manage in the bitflags library itself.

@js2xxx
Copy link

js2xxx commented Mar 25, 2022

I think this feature should move forward provided that the const_fn feature has been stable since long.

@KodrAus
Copy link
Member

KodrAus commented May 4, 2022

Thanks for spiking this out @ldm0! We're still waiting on some kind of const overloading support in Rust itself, but I think that will be the best time for us to take advantage of it in bitflags. I'll go ahead and close this one for now since we won't be doing conditional support for unstable features in this library.

1 similar comment
@KodrAus
Copy link
Member

KodrAus commented May 4, 2022

Thanks for spiking this out @ldm0! We're still waiting on some kind of const overloading support in Rust itself, but I think that will be the best time for us to take advantage of it in bitflags. I'll go ahead and close this one for now since we won't be doing conditional support for unstable features in this library.

@KodrAus KodrAus closed this May 4, 2022
@KodrAus KodrAus closed this May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using bitflags in static structs Can't use generated bitflags to initialise a const
3 participants