/// if it were an [`EnumSet`] in expressions. This can be disabled by adding an `#[enumset(no_ops)]`
/// annotation to the enum.
///
-/// The custom derive for `EnumSetType` automatically implements [`Copy`] and [`Clone`] on the
-/// enum. These are required for the [`EnumSet`] to function.
+/// The custom derive for `EnumSetType` automatically implements [`Copy`], [`Clone`], [`Eq`], and
+/// [`PartialEq`] on the enum. These are required for the [`EnumSet`] to function.
///
/// Any C-like enum is supported, as long as there are no more than 128 variants in the enum,
/// and no variant discriminator is larger than 127.
}
}
-/// Defines enums which can be used with EnumSet.
-///
-/// [`Copy`], [`Clone`], [`PartialOrd`], [`Ord`], [`PartialEq`], [`Eq`], [`Hash`], [`Debug`],
-/// [`Sub`], [`BitAnd`], [`BitOr`], [`BitXor`], and [`Not`] are automatically derived for the enum.
-///
-/// These impls, in general, behave as if the enum variant was an [`EnumSet`] with a single value,
-/// as those created by [`EnumSet::only`].
-#[macro_export]
-#[deprecated(since = "0.3.13", note = "Use `#[derive(EnumSetType)] instead.")]
-macro_rules! enum_set_type {
- ($(#[$enum_attr:meta])* $vis:vis enum $enum_name:ident {
- $($(#[$attr:meta])* $variant:ident),* $(,)*
- } $($rest:tt)*) => {
- $(#[$enum_attr])* #[repr(u8)]
- #[derive($crate::EnumSetType, Debug)]
- $vis enum $enum_name {
- $($(#[$attr])* $variant,)*
- }
-
- enum_set_type!($($rest)*);
- };
- () => { };
-}
-
/// Creates a EnumSet literal, which can be used in const contexts.
///
/// The syntax used is `enum_set!(Type::A | Type::B | Type::C)`. Each variant must be of the same
}
};
- let derives = if attrs.no_derives {
- quote! {}
- } else {
- quote! {
- impl #core::cmp::PartialOrd for #name {
- fn partial_cmp(&self, other: &Self) -> #core::option::Option<#core::cmp::Ordering> {
- (*self as u8).partial_cmp(&(*other as u8))
- }
- }
- impl #core::cmp::Ord for #name {
- fn cmp(&self, other: &Self) -> #core::cmp::Ordering {
- (*self as u8).cmp(&(*other as u8))
- }
- }
- impl #core::cmp::PartialEq for #name {
- fn eq(&self, other: &Self) -> bool {
- (*self as u8) == (*other as u8)
- }
- }
- impl #core::cmp::Eq for #name { }
- impl #core::hash::Hash for #name {
- fn hash<H: #core::hash::Hasher>(&self, state: &mut H) {
- state.write_u8(*self as u8)
- }
- }
- impl #core::clone::Clone for #name {
- fn clone(&self) -> Self {
- *self
- }
- }
- impl #core::marker::Copy for #name { }
- }
- };
-
#[cfg(feature = "serde")]
let expecting_str = format!("a list of {}", name);
#serde_ops
}
+ impl #core::cmp::PartialEq for #name {
+ fn eq(&self, other: &Self) -> bool {
+ (*self as u8) == (*other as u8)
+ }
+ }
+ impl #core::cmp::Eq for #name { }
+ impl #core::clone::Clone for #name {
+ fn clone(&self) -> Self {
+ *self
+ }
+ }
+ impl #core::marker::Copy for #name { }
+
#ops
- #derives
}
}
#[darling(attributes(enumset), default)]
struct EnumsetAttrs {
no_ops: bool,
- no_derives: bool,
serialize_as_list: bool,
#[darling(default)]
serialize_repr: Option<String>,