]> git.lizzy.rs Git - enumset.git/commitdiff
Revert "Don't derive as many traits automatically. Only implement the minimum for...
authorLymia Aluysia <lymia@lymiahugs.com>
Sun, 29 Oct 2017 14:25:10 +0000 (09:25 -0500)
committerLymia Aluysia <lymia@lymiahugs.com>
Sun, 29 Oct 2017 14:25:10 +0000 (09:25 -0500)
This reverts commit 8dbac85b57eb004f3cf92bd5dead361e9cc709d3.

src/lib.rs

index c3b0c13b115dc57c3a30d434ef3885a9ba7dc91f..4adab293ad9fb9b9f2e1aa235759fa14931f1813 100644 (file)
@@ -14,7 +14,6 @@
 //! # 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);
@@ -66,8 +61,7 @@
 //! # #[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)]
@@ -109,7 +102,7 @@ pub trait EnumSetType : Copy {
 
 /// 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 {
@@ -237,28 +230,6 @@ impl <T : EnumSetType> BitOr<T> for EnumSet<T> {
     }
 }
 
-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;
@@ -418,7 +389,7 @@ macro_rules! enum_set_type_internal {
         $($(#[$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,)*
         }
@@ -452,9 +423,6 @@ macro_rules! enum_set_type_internal {
 /// 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
@@ -505,7 +473,6 @@ macro_rules! enum_set_type {
 /// # #[macro_use] extern crate enumset;
 /// # use enumset::*;
 /// # enum_set_type! {
-/// #     #[derive(Debug)]
 /// #     enum Enum { A, B, C }
 /// # }
 /// # fn main() {
@@ -529,7 +496,6 @@ mod test {
     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,
         }
@@ -540,7 +506,6 @@ mod test {
 
     #[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,