@@ -337,7 +337,7 @@ pub use defmt_macros::timestamp;
337337
338338/// Generates a bitflags structure that can be formatted with defmt.
339339///
340- /// This macro is a wrapper around the [`bitflags!`] crate, and provides an (almost) identical
340+ /// This macro is a wrapper around the [`bitflags!`] macro of the bitflags version 1 crate, and provides an (almost) identical
341341/// interface. Refer to [its documentation] for an explanation of the syntax.
342342///
343343/// [its documentation]: https://docs.rs/bitflags/1/bitflags/
@@ -361,6 +361,33 @@ pub use defmt_macros::timestamp;
361361/// const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
362362/// }
363363/// }
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!`][bitflagsv2] macro of the bitflags! version 2 crate, and provides an (almost) identical
376+ /// interface. Refer to [its documentation][bitflagsv2] for an explanation of the syntax.
377+ ///
378+ /// [bitflagsv2]: https://docs.rs/bitflags/2/bitflags/macro.bitflags.html
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+ /// ```
364391/// #[cfg(feature = "bitflagsv2")]
365392/// defmt::bitflagsv2! {
366393/// struct Flags: u32 {
@@ -373,7 +400,6 @@ pub use defmt_macros::timestamp;
373400/// defmt::info!("Flags::ABC: {}", Flags::ABC);
374401/// defmt::info!("Flags::empty(): {}", Flags::empty());
375402/// ```
376- pub use defmt_macros:: bitflags;
377403#[ cfg( feature = "bitflagsv2" ) ]
378404pub use defmt_macros:: bitflagsv2;
379405
0 commit comments