@@ -361,6 +361,33 @@ pub use defmt_macros::timestamp;
361
361
/// const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
362
362
/// }
363
363
/// }
364
+ ///
365
+ /// defmt::info!("Flags::ABC: {}", Flags::ABC);
366
+ /// defmt::info!("Flags::empty(): {}", Flags::empty());
367
+ /// ```
368
+ pub use defmt_macros:: bitflags;
369
+
370
+ /// Users of the defmt crate can enable the bitflagsv2 feature by adding defmt = { features = ["bitflagsv2"] }
371
+ /// to their Cargo.toml. Bitflags version 2 introduces significant improvements over version 1, including a safer
372
+ /// API with the replacement of the unsafe from_bits_unchecked method by the safe from_bits_retain method
373
+ /// and enhanced serialization support via an optional serde feature.
374
+ ///
375
+ /// This macro is a wrapper around the [`bitflags!`] version 2 crate, and provides an (almost) identical
376
+ /// interface. Refer to [its documentation] for an explanation of the syntax.
377
+ ///
378
+ /// [its documentation]: https://docs.rs/bitflags/2/bitflags/
379
+ ///
380
+ /// # Limitations
381
+ ///
382
+ /// This macro only supports bitflags structs represented as one of Rust's built-in unsigned integer
383
+ /// types (`u8`, `u16`, `u32`, `u64`, or `u128`). Custom types are not supported. This restriction
384
+ /// is necessary to support defmt's efficient encoding.
385
+ ///
386
+ /// # Examples
387
+ ///
388
+ /// The example from the bitflagsv2 crate works as-is:
389
+ ///
390
+ /// ```
364
391
/// #[cfg(feature = "bitflagsv2")]
365
392
/// defmt::bitflagsv2! {
366
393
/// struct Flags: u32 {
@@ -373,7 +400,6 @@ pub use defmt_macros::timestamp;
373
400
/// defmt::info!("Flags::ABC: {}", Flags::ABC);
374
401
/// defmt::info!("Flags::empty(): {}", Flags::empty());
375
402
/// ```
376
- pub use defmt_macros:: bitflags;
377
403
#[ cfg( feature = "bitflagsv2" ) ]
378
404
pub use defmt_macros:: bitflagsv2;
379
405
0 commit comments