Make bits() method const #170
Labels
No labels
bug
good first issue
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-bitflags/bitflags#170
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Now that simple const functions are stable in Rust, it'd be useful to make the
bits()method const. I've just added a wrapper around the.bitsfield to do this for a particular use case (assigned a bit-or of flags to another constant that needs to be of the underlying type) - but it'd be nice if the bitflags macro could do it.Hi @raphaelcohn 👋
Sounds good to me! There are probably plenty of other methods on generated bitflags types that could be made
consttoo.Since it's only recently stabilized (in
1.31.0?), I think we should supportconstfunctions where available only on newer compilers. There are a few approaches to doing this, using explicit crate features likeuuiddoes, or by detecting the compiler version using abuild.rsscript likeserdedoes. Personally, I'd lean towards thebuild.rsapproach for this case.If anyone would like to have a go at this but isn't quite sure where to start I'll be happy to help out! Just leave a comment.
@KodrAus - I'd probably slightly favour a
build.rsapproach and compiler version detection. It's a slight shame it's not possible to directly use the#cfgsystem for detecting the rust compiler version, or (for other problems, not this one) rely on a minimum version in Cargo.toml...I believe a RFC is open that allows querying for features
I'd love to try this issue out. Looking over the Serde script now, but I would love any more input you have @KodrAus.
Edit: I see there is an open PR for this issue actually.
This is now supported in
1.0.5when building on newer compilers.