@@ -418,6 +418,38 @@ pub use crate::const_api::ConstToken;
418
418
/// A `BitFlags<T>` is as large as the `T` itself,
419
419
/// and stores one flag per bit.
420
420
///
421
+ /// ## Comparison operators, [`PartialOrd`] and [`Ord`]
422
+ ///
423
+ /// To make it possible to use `BitFlags` as the key of a
424
+ /// [`BTreeMap`][std::collections::BTreeMap], `BitFlags` implements
425
+ /// [`Ord`]. There is no meaningful total order for bitflags,
426
+ /// so the implementation simply compares the integer values of the bits.
427
+ ///
428
+ /// Unfortunately, this means that comparing `BitFlags` with an operator
429
+ /// like `<=` will compile, and return values that are probably useless
430
+ /// and not what you expect. In particular, `<=` does *not* check whether
431
+ /// one value is a subset of the other. Use [`BitFlags::contains`] for that.
432
+ ///
433
+ /// ## Customizing `Default`
434
+ ///
435
+ /// By default, creating an instance of `BitFlags<T>` with `Default` will result
436
+ /// in an empty set. If that's undesirable, you may customize this:
437
+ ///
438
+ /// ```
439
+ /// # use enumflags2::{BitFlags, bitflags};
440
+ /// #[bitflags(default = B | C)]
441
+ /// #[repr(u8)]
442
+ /// #[derive(Copy, Clone, Debug, PartialEq)]
443
+ /// enum MyFlag {
444
+ /// A = 0b0001,
445
+ /// B = 0b0010,
446
+ /// C = 0b0100,
447
+ /// D = 0b1000,
448
+ /// }
449
+ ///
450
+ /// assert_eq!(BitFlags::default(), MyFlag::B | MyFlag::C);
451
+ /// ```
452
+ ///
421
453
/// ## Memory layout
422
454
///
423
455
/// `BitFlags<T>` is marked with the `#[repr(transparent)]` trait, meaning
0 commit comments