//! # use enumset::*;
//! enum_set_type! {
//! /// Documentation for the enum
-//! #[derive(Debug)]
//! pub enum Enum {
//! A, B, C, D, E, F, G,
//! #[doc(hidden)] __NonExhaustive,
//! # #[macro_use] extern crate enumset;
//! # use enumset::*;
//! # enum_set_type! {
-//! # #[derive(Debug)]
-//! # pub enum Enum {
-//! # A, B, C, D, E, F, G,
-//! # }
+//! # pub enum Enum {
+//! # A, B, C, D, E, F, G,
+//! # }
//! # }
//! # fn main() {
//! let new_set = Enum::A | Enum::C | Enum::G;
//! # #[macro_use] extern crate enumset;
//! # use enumset::*;
//! # enum_set_type! {
-//! # #[derive(Debug)]
-//! # pub enum Enum {
-//! # A, B, C, D, E, F, G,
-//! # }
+//! # enum Enum { A, B, C }
//! # }
//! # fn main() {
//! const CONST_SET: EnumSet<Enum> = enum_set!(Enum, Enum::A | Enum::B);
//! # #[macro_use] extern crate enumset;
//! # use enumset::*;
//! # enum_set_type! {
-//! # #[derive(Debug)]
-//! # pub enum Enum {
+//! # pub enum Enum {
//! # A, B, C, D, E, F, G,
//! # }
//! # }
//! [`enum_set!`]: ./macro.enum_set.html
//! [`enum_set_type!`]: ./macro.enum_set_type.html
-use std::cmp::*;
use std::fmt;
use std::fmt::{Debug, Formatter};
-use std::hash::*;
+use std::hash::Hash;
use std::ops::*;
#[doc(hidden)]
/// An efficient set type for enums created with the [`enum_set_type!`](./macro.enum_set_type.html)
/// macro.
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct EnumSet<T : EnumSetType>(#[doc(hidden)] pub T::Repr);
impl <T : EnumSetType> EnumSet<T> {
fn mask(bit: u8) -> T::Repr {
}
}
-impl <T : EnumSetType> PartialOrd for EnumSet<T> {
- fn partial_cmp(&self, other: &EnumSet<T>) -> Option<Ordering> {
- self.0.partial_cmp(&other.0)
- }
-}
-impl <T : EnumSetType> Ord for EnumSet<T> {
- fn cmp(&self, other: &Self) -> Ordering {
- self.0.cmp(&other.0)
- }
-}
-impl <T : EnumSetType> PartialEq for EnumSet<T> {
- fn eq(&self, other: &EnumSet<T>) -> bool {
- self.0.eq(&other.0)
- }
-}
-impl <T : EnumSetType> Eq for EnumSet<T> { }
-impl <T : EnumSetType> Hash for EnumSet<T> {
- fn hash<H: Hasher>(&self, state: &mut H) {
- self.0.hash(state)
- }
-}
-
impl <T : EnumSetType + Debug> Debug for EnumSet<T> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let mut is_first = true;
$($(#[$attr:meta])* $variant:ident,)*
}) => {
$(#[$enum_attr])* #[repr(u8)]
- #[derive(Copy, Clone)]
+ #[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
$($vis)* enum $enum_name {
$($(#[$attr])* $variant,)*
}
/// While attributes and documentation can be attached to the enums, the variants may not
/// contain data.
///
-/// `Copy` and `Clone` are automatically derived for the enums. Other traits must be manually
-/// derived or implemented.
-///
/// # Examples
///
/// ```rust
/// # #[macro_use] extern crate enumset;
/// # use enumset::*;
/// # enum_set_type! {
-/// # #[derive(Debug)]
/// # enum Enum { A, B, C }
/// # }
/// # fn main() {
use super::*;
enum_set_type! {
- #[derive(Debug)]
enum Enum {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
}
#[cfg(feature = "i128")]
enum_set_type! {
- #[derive(Debug)]
enum LargeEnum {
_00, _01, _02, _03, _04, _05, _06, _07,
_10, _11, _12, _13, _14, _15, _16, _17,