Skip to content

Commit

Permalink
Make from_bits a const fn
Browse files Browse the repository at this point in the history
'if' now works in 'const fn as of rust 1.4.6 (https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html).

I would love to have 'from_bits' be a 'const fn' because it is the safest from_* function.
  • Loading branch information
Benjamin Prosnitz committed Oct 19, 2020
1 parent 15e911c commit c3fb4e6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -617,7 +617,7 @@ macro_rules! __impl_bitflags {
/// Convert from underlying bit representation, unless that
/// representation contains bits that do not correspond to a flag.
#[inline]
pub fn from_bits(bits: $T) -> $crate::_core::option::Option<$BitFlags> {
pub const fn from_bits(bits: $T) -> $crate::_core::option::Option<$BitFlags> {
if (bits & !$BitFlags::all().bits()) == 0 {
$crate::_core::option::Option::Some($BitFlags { bits })
} else {
Expand Down

0 comments on commit c3fb4e6

Please sign in to comment.