-
-
Notifications
You must be signed in to change notification settings - Fork 103
Allow bitflags v1 and v2 to coexist #894
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,9 @@ use crate::{Format, Formatter, Str}; | |||||
pub use self::integers::*; | ||||||
pub use bitflags::bitflags; | ||||||
|
||||||
#[cfg(feature = "bitflagsv2")] | ||||||
pub use bitflagsv2::bitflags as bitflagsv2; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may I ask for the
Suggested change
I need them, and other users might want them too, for a project and would prefer relying on the version installed by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's reasonable - perhaps for v2 import the whole crate like: pub use bitflags::{bitflags, self};
#[cfg(feature = "bitflagsv2")]
pub use bitflagsv2::{bitflags as bitflagsv2, self}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @manushT any thoughts on this one? |
||||||
|
||||||
pub trait UnsignedInt {} | ||||||
impl UnsignedInt for u8 {} | ||||||
impl UnsignedInt for u16 {} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
INFO Flags::empty(): FLAG_0 | ||
INFO Flags::empty(): Flags(0x0) (fmt::Debug) | ||
INFO Flags::all(): FLAG_1 | FLAG_2 | FLAG_7 | FLAG_7_COPY | ||
INFO Flags::all(): Flags(FLAG_1 | FLAG_2 | FLAG_7) (fmt::Debug) | ||
INFO Flags::FLAG_1: FLAG_1 | ||
INFO Flags::FLAG_1: Flags(FLAG_1) (fmt::Debug) | ||
INFO Flags::FLAG_7: FLAG_7 | FLAG_7_COPY | ||
INFO Flags::FLAG_7: Flags(FLAG_7) (fmt::Debug) | ||
INFO LargeFlags::ALL: MSB | ALL | NON_LITERAL | ||
INFO LargeFlags::ALL: LargeFlags(MSB | ALL) (fmt::Debug) | ||
INFO LargeFlags::empty(): (empty) | ||
INFO LargeFlags::empty(): LargeFlags(0x0) (fmt::Debug) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#![no_std] | ||
#![no_main] | ||
#![allow(clippy::bad_bit_mask)] | ||
|
||
use cortex_m_rt::entry; | ||
use cortex_m_semihosting::debug; | ||
use defmt::{bitflagsv2, Debug2Format}; | ||
|
||
use defmt_semihosting as _; // global logger | ||
|
||
bitflagsv2! { | ||
#[derive(Debug)] | ||
struct Flags: u8 { | ||
#[cfg(not(never))] | ||
const FLAG_0 = 0b00; | ||
const FLAG_1 = 0b01; | ||
const FLAG_2 = 0b10; | ||
const FLAG_7 = 1 << 7; | ||
const FLAG_7_COPY = Self::FLAG_7.bits(); | ||
#[cfg(never)] | ||
const CFGD_OUT = 1; | ||
} | ||
} | ||
|
||
bitflagsv2! { | ||
#[derive(Debug)] | ||
struct LargeFlags: u128 { | ||
const MSB = 1 << 127; | ||
const ALL = !0; | ||
const NON_LITERAL = compute_flag_value(0x346934553632462); | ||
} | ||
} | ||
|
||
const fn compute_flag_value(x: u128) -> u128 { | ||
x ^ 0xdeadbeef | ||
} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
defmt::info!("Flags::empty(): {}", Flags::empty()); | ||
defmt::info!( | ||
"Flags::empty(): {} (fmt::Debug)", | ||
Debug2Format(&Flags::empty()) | ||
); | ||
defmt::info!("Flags::all(): {}", Flags::all()); | ||
defmt::info!("Flags::all(): {} (fmt::Debug)", Debug2Format(&Flags::all())); | ||
defmt::info!("Flags::FLAG_1: {}", Flags::FLAG_1); | ||
defmt::info!( | ||
"Flags::FLAG_1: {} (fmt::Debug)", | ||
Debug2Format(&Flags::FLAG_1) | ||
); | ||
defmt::info!("Flags::FLAG_7: {}", Flags::FLAG_7); | ||
defmt::info!( | ||
"Flags::FLAG_7: {} (fmt::Debug)", | ||
Debug2Format(&Flags::FLAG_7) | ||
); | ||
|
||
defmt::info!("LargeFlags::ALL: {}", LargeFlags::ALL); | ||
defmt::info!( | ||
"LargeFlags::ALL: {} (fmt::Debug)", | ||
Debug2Format(&LargeFlags::ALL) | ||
); | ||
defmt::info!("LargeFlags::empty(): {}", LargeFlags::empty()); | ||
defmt::info!( | ||
"LargeFlags::empty(): {} (fmt::Debug)", | ||
Debug2Format(&LargeFlags::empty()) | ||
); | ||
|
||
loop { | ||
debug::exit(debug::EXIT_SUCCESS) | ||
} | ||
} | ||
|
||
// like `panic-semihosting` but doesn't print to stdout (that would corrupt the defmt stream) | ||
#[cfg(target_os = "none")] | ||
#[panic_handler] | ||
fn panic(_: &core::panic::PanicInfo) -> ! { | ||
loop { | ||
debug::exit(debug::EXIT_FAILURE) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.