Skip to content

Commit ce922bb

Browse files
committed
Adds documentation for bitflagsv2
1 parent ac6ddb3 commit ce922bb

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

defmt/src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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!`] 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+
/// ```
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")]
378404
pub use defmt_macros::bitflagsv2;
379405

0 commit comments

Comments
 (0)