2 #![forbid(missing_docs)]
4 //! A library for defining enums that can be used in compact bit sets. It supports enums up to 128
5 //! variants, and has a macro to use these sets in constants.
7 //! For serde support, enable the `serde` feature.
9 //! # Defining enums for use with EnumSet
11 //! Enums to be used with [`EnumSet`] should be defined using `#[derive(EnumSetType)]`:
15 //! #[derive(EnumSetType, Debug)]
17 //! A, B, C, D, E, F, G,
21 //! For more information on more advanced use cases, see the documentation for [`EnumSetType`].
23 //! # Working with EnumSets
25 //! EnumSets can be constructed via [`EnumSet::new()`] like a normal set. In addition,
26 //! `#[derive(EnumSetType)]` creates operator overloads that allow you to create EnumSets like so:
30 //! # #[derive(EnumSetType, Debug)] pub enum Enum { A, B, C, D, E, F, G }
31 //! let new_set = Enum::A | Enum::C | Enum::G;
32 //! assert_eq!(new_set.len(), 3);
35 //! All bitwise operations you would expect to work on bitsets also work on both EnumSets and
36 //! enums with `#[derive(EnumSetType)]`:
39 //! # #[derive(EnumSetType, Debug)] pub enum Enum { A, B, C, D, E, F, G }
40 //! // Intersection of sets
41 //! assert_eq!((Enum::A | Enum::B) & Enum::C, EnumSet::empty());
42 //! assert_eq!((Enum::A | Enum::B) & Enum::A, Enum::A);
43 //! assert_eq!(Enum::A & Enum::B, EnumSet::empty());
45 //! // Symmetric difference of sets
46 //! assert_eq!((Enum::A | Enum::B) ^ (Enum::B | Enum::C), Enum::A | Enum::C);
47 //! assert_eq!(Enum::A ^ Enum::C, Enum::A | Enum::C);
49 //! // Difference of sets
50 //! assert_eq!((Enum::A | Enum::B | Enum::C) - Enum::B, Enum::A | Enum::C);
52 //! // Complement of sets
53 //! assert_eq!(!(Enum::E | Enum::G), Enum::A | Enum::B | Enum::C | Enum::D | Enum::F);
56 //! The [`enum_set!`] macro allows you to create EnumSets in constant contexts:
60 //! # #[derive(EnumSetType, Debug)] pub enum Enum { A, B, C, D, E, F, G }
61 //! const CONST_SET: EnumSet<Enum> = enum_set!(Enum::A | Enum::B);
62 //! assert_eq!(CONST_SET, Enum::A | Enum::B);
65 //! Mutable operations on the [`EnumSet`] otherwise similarly to Rust's builtin sets:
69 //! # #[derive(EnumSetType, Debug)] pub enum Enum { A, B, C, D, E, F, G }
70 //! let mut set = EnumSet::new();
71 //! set.insert(Enum::A);
72 //! set.insert_all(Enum::E | Enum::G);
73 //! assert!(set.contains(Enum::A));
74 //! assert!(!set.contains(Enum::B));
75 //! assert_eq!(set, Enum::A | Enum::E | Enum::G);
78 pub use enumset_derive::EnumSetType;
80 use core::cmp::Ordering;
82 use core::fmt::{Debug, Formatter};
83 use core::hash::{Hash, Hasher};
84 use core::iter::{FromIterator, Sum};
88 /// Everything in this module is internal API and may change at any time.
92 /// A reexport of core to allow our macros to be generic to std vs core.
93 pub use ::core as core_export;
95 /// A reexport of serde so there is no requirement to depend on serde.
96 #[cfg(feature = "serde")] pub use serde2 as serde;
98 /// The actual members of EnumSetType. Put here to avoid polluting global namespaces.
99 pub unsafe trait EnumSetTypePrivate {
100 /// The underlying type used to store the bitset.
101 type Repr: EnumSetTypeRepr;
102 /// A mask of bits that are valid in the bitset.
103 const ALL_BITS: Self::Repr;
105 /// Converts an enum of this type into its bit position.
106 fn enum_into_u32(self) -> u32;
107 /// Converts a bit position into an enum value.
108 unsafe fn enum_from_u32(val: u32) -> Self;
110 /// Serializes the `EnumSet`.
112 /// This and `deserialize` are part of the `EnumSetType` trait so the procedural derive
113 /// can control how `EnumSet` is serialized.
114 #[cfg(feature = "serde")]
115 fn serialize<S: serde::Serializer>(set: EnumSet<Self>, ser: S) -> Result<S::Ok, S::Error>
116 where Self: EnumSetType;
117 /// Deserializes the `EnumSet`.
118 #[cfg(feature = "serde")]
119 fn deserialize<'de, D: serde::Deserializer<'de>>(de: D) -> Result<EnumSet<Self>, D::Error>
120 where Self: EnumSetType;
123 use crate::__internal::EnumSetTypePrivate;
124 #[cfg(feature = "serde")] use crate::__internal::serde;
125 #[cfg(feature = "serde")] use crate::serde::{Serialize, Deserialize};
128 use crate::repr::EnumSetTypeRepr;
130 /// The trait used to define enum types that may be used with [`EnumSet`].
132 /// This trait should be implemented using `#[derive(EnumSetType)]`. Its internal structure is
133 /// not stable, and may change at any time.
137 /// Any C-like enum is supported, as long as there are no more than 128 variants in the enum,
138 /// and no variant discriminator is larger than 127.
140 /// The custom derive for [`EnumSetType`] automatically creates implementations of [`PartialEq`],
141 /// [`Sub`], [`BitAnd`], [`BitOr`], [`BitXor`], and [`Not`] allowing the enum to be used as
142 /// if it were an [`EnumSet`] in expressions. This can be disabled by adding an `#[enumset(no_ops)]`
143 /// annotation to the enum.
145 /// The custom derive for `EnumSetType` automatically implements [`Copy`], [`Clone`], [`Eq`], and
146 /// [`PartialEq`] on the enum. These are required for the [`EnumSet`] to function. These automatic
147 /// implementations can be disabled by adding an `#[enumset(no_super_impls)]` annotation to
148 /// the enum, but they must still be implemented. Disabling the automatic implementations can be
149 /// useful if, for example, you are using a code generator that already derives these traits. Note
150 /// that the `PartialEq` implementation, if not derived, **must** produce the same results as a
151 /// derived implementation would, or else `EnumSet` will not work correctly.
153 /// In addition, if you have renamed the `enumset` crate in your crate, you can use the
154 /// `#[enumset(crate_name = "enumset2")]` attribute to tell the custom derive to use that name
157 /// Attributes controlling the serialization of an `EnumSet` are documented in
158 /// [its documentation](./struct.EnumSet.html#serialization).
162 /// Deriving a plain EnumSetType:
165 /// # use enumset::*;
166 /// #[derive(EnumSetType)]
168 /// A, B, C, D, E, F, G,
172 /// Deriving a sparse EnumSetType:
175 /// # use enumset::*;
176 /// #[derive(EnumSetType)]
177 /// pub enum SparseEnum {
178 /// A = 10, B = 20, C = 30, D = 127,
182 /// Deriving an EnumSetType without adding ops:
185 /// # use enumset::*;
186 /// #[derive(EnumSetType)]
187 /// #[enumset(no_ops)]
188 /// pub enum NoOpsEnum {
189 /// A, B, C, D, E, F, G,
192 pub unsafe trait EnumSetType: Copy + Eq + EnumSetTypePrivate { }
194 /// An efficient set type for enums.
196 /// It is implemented using a bitset stored using the smallest integer that can fit all bits
197 /// in the underlying enum. In general, an enum variant with a numeric value of `n` is stored in
198 /// the nth least significant bit (corresponding with a mask of, e.g. `1 << enum as u32`).
202 /// When the `serde` feature is enabled, `EnumSet`s can be serialized and deserialized using
203 /// the `serde` crate. The exact serialization format can be controlled with additional attributes
204 /// on the enum type. These attributes are valid regardless of whether the `serde` feature
207 /// By default, `EnumSet`s serialize by directly writing out the underlying bitset as an integer
208 /// of the smallest type that can fit in the underlying enum. You can add a
209 /// `#[enumset(serialize_repr = "u8")]` attribute to your enum to control the integer type used
210 /// for serialization. This can be important for avoiding unintentional breaking changes when
211 /// `EnumSet`s are serialized with formats like `bincode`.
213 /// By default, unknown bits are ignored and silently removed from the bitset. To override this
214 /// behavior, you can add a `#[enumset(serialize_deny_unknown)]` attribute. This will cause
215 /// deserialization to fail if an invalid bit is set.
217 /// In addition, the `#[enumset(serialize_as_list)]` attribute causes the `EnumSet` to be
218 /// instead serialized as a list of enum variants. This requires your enum type implement
219 /// [`Serialize`] and [`Deserialize`]. Note that this is a breaking change
220 #[derive(Copy, Clone, PartialEq, Eq)]
222 pub struct EnumSet<T: EnumSetType> {
224 /// This is public due to the [`enum_set!`] macro.
225 /// This is **NOT** public API and may change at any time.
226 pub __priv_repr: T::Repr
228 impl <T: EnumSetType> EnumSet<T> {
229 // Returns all bits valid for the enum
231 fn all_bits() -> T::Repr {
235 /// Creates an empty `EnumSet`.
237 pub fn new() -> Self {
238 EnumSet { __priv_repr: T::Repr::empty() }
241 /// Returns an `EnumSet` containing a single element.
243 pub fn only(t: T) -> Self {
244 let mut set = Self::new();
249 /// Creates an empty `EnumSet`.
251 /// This is an alias for [`EnumSet::new`].
253 pub fn empty() -> Self {
257 /// Returns an `EnumSet` containing all valid variants of the enum.
259 pub fn all() -> Self {
260 EnumSet { __priv_repr: Self::all_bits() }
263 /// Total number of bits used by this type. Note that the actual amount of space used is
264 /// rounded up to the next highest integer type (`u8`, `u16`, `u32`, `u64`, or `u128`).
266 /// This is the same as [`EnumSet::variant_count`] except in enums with "sparse" variants.
267 /// (e.g. `enum Foo { A = 10, B = 20 }`)
269 pub fn bit_width() -> u32 {
270 T::Repr::WIDTH - T::ALL_BITS.leading_zeros()
273 /// The number of valid variants that this type can contain.
275 /// This is the same as [`EnumSet::bit_width`] except in enums with "sparse" variants.
276 /// (e.g. `enum Foo { A = 10, B = 20 }`)
278 pub fn variant_count() -> u32 {
279 T::ALL_BITS.count_ones()
282 /// Returns the number of elements in this set.
284 pub fn len(&self) -> usize {
285 self.__priv_repr.count_ones() as usize
287 /// Returns `true` if the set contains no elements.
289 pub fn is_empty(&self) -> bool {
290 self.__priv_repr.is_empty()
292 /// Removes all elements from the set.
294 pub fn clear(&mut self) {
295 self.__priv_repr = T::Repr::empty()
298 /// Returns `true` if `self` has no elements in common with `other`. This is equivalent to
299 /// checking for an empty intersection.
301 pub fn is_disjoint(&self, other: Self) -> bool {
302 (*self & other).is_empty()
304 /// Returns `true` if the set is a superset of another, i.e., `self` contains at least all the
305 /// values in `other`.
307 pub fn is_superset(&self, other: Self) -> bool {
308 (*self & other).__priv_repr == other.__priv_repr
310 /// Returns `true` if the set is a subset of another, i.e., `other` contains at least all
311 /// the values in `self`.
313 pub fn is_subset(&self, other: Self) -> bool {
314 other.is_superset(*self)
317 /// Returns a set containing any elements present in either set.
319 pub fn union(&self, other: Self) -> Self {
320 EnumSet { __priv_repr: self.__priv_repr | other.__priv_repr }
322 /// Returns a set containing every element present in both sets.
324 pub fn intersection(&self, other: Self) -> Self {
325 EnumSet { __priv_repr: self.__priv_repr & other.__priv_repr }
327 /// Returns a set containing element present in `self` but not in `other`.
329 pub fn difference(&self, other: Self) -> Self {
330 EnumSet { __priv_repr: self.__priv_repr.and_not(other.__priv_repr) }
332 /// Returns a set containing every element present in either `self` or `other`, but is not
335 pub fn symmetrical_difference(&self, other: Self) -> Self {
336 EnumSet { __priv_repr: self.__priv_repr ^ other.__priv_repr }
338 /// Returns a set containing all enum variants not in this set.
340 pub fn complement(&self) -> Self {
341 EnumSet { __priv_repr: !self.__priv_repr & Self::all_bits() }
344 /// Checks whether this set contains a value.
346 pub fn contains(&self, value: T) -> bool {
347 self.__priv_repr.has_bit(value.enum_into_u32())
350 /// Adds a value to this set.
352 /// If the set did not have this value present, `true` is returned.
354 /// If the set did have this value present, `false` is returned.
356 pub fn insert(&mut self, value: T) -> bool {
357 let contains = !self.contains(value);
358 self.__priv_repr.add_bit(value.enum_into_u32());
361 /// Removes a value from this set. Returns whether the value was present in the set.
363 pub fn remove(&mut self, value: T) -> bool {
364 let contains = self.contains(value);
365 self.__priv_repr.remove_bit(value.enum_into_u32());
369 /// Adds all elements in another set to this one.
371 pub fn insert_all(&mut self, other: Self) {
372 self.__priv_repr = self.__priv_repr | other.__priv_repr
374 /// Removes all values in another set from this one.
376 pub fn remove_all(&mut self, other: Self) {
377 self.__priv_repr = self.__priv_repr.and_not(other.__priv_repr);
380 /// Creates an iterator over the values in this set.
382 /// Note that iterator invalidation is impossible as the iterator contains a copy of this type,
383 /// rather than holding a reference to it.
384 pub fn iter(&self) -> EnumSetIter<T> {
385 EnumSetIter::new(*self)
389 /// Helper macro for generating conversion functions.
390 macro_rules! conversion_impls {
393 $underlying:ty, $underlying_str:expr,
394 $from_fn:ident $to_fn:ident $from_fn_opt:ident $to_fn_opt:ident,
395 $from:ident $try_from:ident $from_truncated:ident
396 $to:ident $try_to:ident $to_truncated:ident
399 impl <T : EnumSetType> EnumSet<T> {$(
400 #[doc = "Returns a `"]
401 #[doc = $underlying_str]
402 #[doc = "` representing the elements of this set.\n\nIf the underlying bitset will \
404 #[doc = $underlying_str]
405 #[doc = "`, this method will panic."]
407 pub fn $to(&self) -> $underlying {
408 self.$try_to().expect("Bitset will not fit into this type.")
411 #[doc = "Tries to return a `"]
412 #[doc = $underlying_str]
413 #[doc = "` representing the elements of this set.\n\nIf the underlying bitset will \
415 #[doc = $underlying_str]
416 #[doc = "`, this method will instead return `None`."]
418 pub fn $try_to(&self) -> Option<$underlying> {
419 EnumSetTypeRepr::$to_fn_opt(&self.__priv_repr)
422 #[doc = "Returns a truncated `"]
423 #[doc = $underlying_str]
424 #[doc = "` representing the elements of this set.\n\nIf the underlying bitset will \
426 #[doc = $underlying_str]
427 #[doc = "`, this method will truncate any bits that don't fit."]
429 pub fn $to_truncated(&self) -> $underlying {
430 EnumSetTypeRepr::$to_fn(&self.__priv_repr)
433 #[doc = "Constructs a bitset from a `"]
434 #[doc = $underlying_str]
435 #[doc = "`.\n\nIf a bit that doesn't correspond to an enum variant is set, this \
438 pub fn $from(bits: $underlying) -> Self {
439 Self::$try_from(bits).expect("Bitset contains invalid variants.")
442 #[doc = "Attempts to constructs a bitset from a `"]
443 #[doc = $underlying_str]
444 #[doc = "`.\n\nIf a bit that doesn't correspond to an enum variant is set, this \
445 method will return `None`."]
447 pub fn $try_from(bits: $underlying) -> Option<Self> {
448 let bits = T::Repr::$from_fn_opt(bits);
449 let mask = Self::all().__priv_repr;
450 bits.and_then(|bits| if bits.and_not(mask).is_empty() {
451 Some(EnumSet { __priv_repr: bits })
457 #[doc = "Constructs a bitset from a `"]
458 #[doc = $underlying_str]
459 #[doc = "`, ignoring invalid variants."]
461 pub fn $from_truncated(bits: $underlying) -> Self {
462 let mask = Self::all().$to_truncated();
463 let bits = <T::Repr as EnumSetTypeRepr>::$from_fn(bits & mask);
464 EnumSet { __priv_repr: bits }
470 for_num!(u8, "u8", from_u8 to_u8 from_u8_opt to_u8_opt,
471 from_u8 try_from_u8 from_u8_truncated as_u8 try_as_u8 as_u8_truncated);
472 for_num!(u16, "u16", from_u16 to_u16 from_u16_opt to_u16_opt,
473 from_u16 try_from_u16 from_u16_truncated as_u16 try_as_u16 as_u16_truncated);
474 for_num!(u32, "u32", from_u32 to_u32 from_u32_opt to_u32_opt,
475 from_u32 try_from_u32 from_u32_truncated as_u32 try_as_u32 as_u32_truncated);
476 for_num!(u64, "u64", from_u64 to_u64 from_u64_opt to_u64_opt,
477 from_u64 try_from_u64 from_u64_truncated as_u64 try_as_u64 as_u64_truncated);
478 for_num!(u128, "u128", from_u128 to_u128 from_u128_opt to_u128_opt,
479 from_u128 try_from_u128 from_u128_truncated as_u128 try_as_u128 as_u128_truncated);
480 for_num!(usize, "usize", from_usize to_usize from_usize_opt to_usize_opt,
481 from_usize try_from_usize from_usize_truncated
482 as_usize try_as_usize as_usize_truncated);
485 impl <T: EnumSetType> Default for EnumSet<T> {
486 /// Returns an empty set.
487 fn default() -> Self {
492 impl <T: EnumSetType> IntoIterator for EnumSet<T> {
494 type IntoIter = EnumSetIter<T>;
496 fn into_iter(self) -> Self::IntoIter {
500 impl <T: EnumSetType> Sum for EnumSet<T> {
501 fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
502 iter.fold(EnumSet::empty(), |a, v| a | v)
505 impl <'a, T: EnumSetType> Sum<&'a EnumSet<T>> for EnumSet<T> {
506 fn sum<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
507 iter.fold(EnumSet::empty(), |a, v| a | *v)
510 impl <T: EnumSetType> Sum<T> for EnumSet<T> {
511 fn sum<I: Iterator<Item=T>>(iter: I) -> Self {
512 iter.fold(EnumSet::empty(), |a, v| a | v)
515 impl <'a, T: EnumSetType> Sum<&'a T> for EnumSet<T> {
516 fn sum<I: Iterator<Item=&'a T>>(iter: I) -> Self {
517 iter.fold(EnumSet::empty(), |a, v| a | *v)
521 impl <T: EnumSetType, O: Into<EnumSet<T>>> Sub<O> for EnumSet<T> {
524 fn sub(self, other: O) -> Self::Output {
525 self.difference(other.into())
528 impl <T: EnumSetType, O: Into<EnumSet<T>>> BitAnd<O> for EnumSet<T> {
531 fn bitand(self, other: O) -> Self::Output {
532 self.intersection(other.into())
535 impl <T: EnumSetType, O: Into<EnumSet<T>>> BitOr<O> for EnumSet<T> {
538 fn bitor(self, other: O) -> Self::Output {
539 self.union(other.into())
542 impl <T: EnumSetType, O: Into<EnumSet<T>>> BitXor<O> for EnumSet<T> {
545 fn bitxor(self, other: O) -> Self::Output {
546 self.symmetrical_difference(other.into())
550 impl <T: EnumSetType, O: Into<EnumSet<T>>> SubAssign<O> for EnumSet<T> {
552 fn sub_assign(&mut self, rhs: O) {
556 impl <T: EnumSetType, O: Into<EnumSet<T>>> BitAndAssign<O> for EnumSet<T> {
558 fn bitand_assign(&mut self, rhs: O) {
562 impl <T: EnumSetType, O: Into<EnumSet<T>>> BitOrAssign<O> for EnumSet<T> {
564 fn bitor_assign(&mut self, rhs: O) {
568 impl <T: EnumSetType, O: Into<EnumSet<T>>> BitXorAssign<O> for EnumSet<T> {
570 fn bitxor_assign(&mut self, rhs: O) {
575 impl <T: EnumSetType> Not for EnumSet<T> {
578 fn not(self) -> Self::Output {
583 impl <T: EnumSetType> From<T> for EnumSet<T> {
584 fn from(t: T) -> Self {
589 impl <T: EnumSetType> PartialEq<T> for EnumSet<T> {
590 fn eq(&self, other: &T) -> bool {
591 self.__priv_repr == EnumSet::only(*other).__priv_repr
594 impl <T: EnumSetType + Debug> Debug for EnumSet<T> {
595 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
596 let mut is_first = true;
597 f.write_str("EnumSet(")?;
598 for v in self.iter() {
599 if !is_first { f.write_str(" | ")?; }
608 #[allow(clippy::derive_hash_xor_eq)] // This impl exists to change trait bounds only.
609 impl <T: EnumSetType> Hash for EnumSet<T> {
610 fn hash<H: Hasher>(&self, state: &mut H) {
611 self.__priv_repr.hash(state)
614 impl <T: EnumSetType> PartialOrd for EnumSet<T> {
615 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
616 self.__priv_repr.partial_cmp(&other.__priv_repr)
619 impl <T: EnumSetType> Ord for EnumSet<T> {
620 fn cmp(&self, other: &Self) -> Ordering {
621 self.__priv_repr.cmp(&other.__priv_repr)
625 #[cfg(feature = "serde")]
626 impl <T: EnumSetType> Serialize for EnumSet<T> {
627 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
628 T::serialize(*self, serializer)
632 #[cfg(feature = "serde")]
633 impl <'de, T: EnumSetType> Deserialize<'de> for EnumSet<T> {
634 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
635 T::deserialize(deserializer)
639 /// The iterator used by [`EnumSet`]s.
640 #[derive(Clone, Debug)]
641 pub struct EnumSetIter<T: EnumSetType> {
644 impl <T: EnumSetType> EnumSetIter<T> {
645 fn new(set: EnumSet<T>) -> EnumSetIter<T> {
649 impl <T: EnumSetType> Iterator for EnumSetIter<T> {
652 fn next(&mut self) -> Option<Self::Item> {
653 if self.set.is_empty() {
656 let bit = self.set.__priv_repr.trailing_zeros();
657 self.set.__priv_repr.remove_bit(bit);
658 unsafe { Some(T::enum_from_u32(bit)) }
661 fn size_hint(&self) -> (usize, Option<usize>) {
662 let left = self.set.len();
667 impl<T: EnumSetType> ExactSizeIterator for EnumSetIter<T> {}
669 impl<T: EnumSetType> Extend<T> for EnumSet<T> {
670 fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
671 iter.into_iter().for_each(|v| { self.insert(v); });
675 impl<T: EnumSetType> FromIterator<T> for EnumSet<T> {
676 fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
677 let mut set = EnumSet::default();
683 impl<T: EnumSetType> Extend<EnumSet<T>> for EnumSet<T> {
684 fn extend<I: IntoIterator<Item = EnumSet<T>>>(&mut self, iter: I) {
685 iter.into_iter().for_each(|v| { self.insert_all(v); });
689 impl<T: EnumSetType> FromIterator<EnumSet<T>> for EnumSet<T> {
690 fn from_iter<I: IntoIterator<Item = EnumSet<T>>>(iter: I) -> Self {
691 let mut set = EnumSet::default();
697 /// Creates a EnumSet literal, which can be used in const contexts.
699 /// The syntax used is `enum_set!(Type::A | Type::B | Type::C)`. Each variant must be of the same
700 /// type, or a error will occur at compile-time.
702 /// This macro accepts trailing `|`s to allow easier use in other macros.
707 /// # use enumset::*;
708 /// # #[derive(EnumSetType, Debug)] enum Enum { A, B, C }
709 /// const CONST_SET: EnumSet<Enum> = enum_set!(Enum::A | Enum::B);
710 /// assert_eq!(CONST_SET, Enum::A | Enum::B);
713 /// This macro is strongly typed. For example, the following will not compile:
716 /// # use enumset::*;
717 /// # #[derive(EnumSetType, Debug)] enum Enum { A, B, C }
718 /// # #[derive(EnumSetType, Debug)] enum Enum2 { A, B, C }
719 /// let type_error = enum_set!(Enum::A | Enum2::B);
722 macro_rules! enum_set {
724 $crate::EnumSet { __priv_repr: 0 }
726 ($value:path $(|)*) => {
728 #[allow(deprecated)] let value = $value.__impl_enumset_internal__const_only();
732 ($value:path | $($rest:path)|* $(|)*) => {
734 #[allow(deprecated)] let value = $value.__impl_enumset_internal__const_only();
735 $(#[allow(deprecated)] let value = $rest.__impl_enumset_internal__const_merge(value);)*