| 1 | #[cfg(not(any( |
| 2 | feature = "Debug", |
| 3 | feature = "Clone", |
| 4 | feature = "Copy", |
| 5 | feature = "PartialEq", |
| 6 | feature = "Eq", |
| 7 | feature = "PartialOrd", |
| 8 | feature = "Ord", |
| 9 | feature = "Hash", |
| 10 | feature = "Default", |
| 11 | feature = "Deref", |
| 12 | feature = "DerefMut", |
| 13 | feature = "Into", |
| 14 | )))] |
| 15 | compile_error!("at least one of the trait features must be enabled"); |
| 16 | |
| 17 | use enum_ordinalize::Ordinalize; |
| 18 | use syn::Path; |
| 19 | |
| 20 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ordinalize)] |
| 21 | #[ordinalize(impl_trait = false)] |
| 22 | #[ordinalize(variants(pub(crate) const VARIANTS))] |
| 23 | pub(crate) enum Trait { |
| 24 | #[cfg(feature = "Debug")] |
| 25 | Debug, |
| 26 | #[cfg(feature = "Clone")] |
| 27 | Clone, |
| 28 | #[cfg(feature = "Copy")] |
| 29 | Copy, |
| 30 | #[cfg(feature = "PartialEq")] |
| 31 | PartialEq, |
| 32 | #[cfg(feature = "Eq")] |
| 33 | Eq, |
| 34 | #[cfg(feature = "PartialOrd")] |
| 35 | PartialOrd, |
| 36 | #[cfg(feature = "Ord")] |
| 37 | Ord, |
| 38 | #[cfg(feature = "Hash")] |
| 39 | Hash, |
| 40 | #[cfg(feature = "Default")] |
| 41 | Default, |
| 42 | #[cfg(feature = "Deref")] |
| 43 | Deref, |
| 44 | #[cfg(feature = "DerefMut")] |
| 45 | DerefMut, |
| 46 | #[cfg(feature = "Into")] |
| 47 | Into, |
| 48 | |
| 49 | _Nothing, |
| 50 | } |
| 51 | |
| 52 | impl Trait { |
| 53 | #[inline] |
| 54 | pub(crate) fn from_path(path: &Path) -> Option<Self> { |
| 55 | let ident_string = match path.get_ident() { |
| 56 | Some(ident) => ident.to_string(), |
| 57 | None => return None, |
| 58 | }; |
| 59 | |
| 60 | match ident_string.as_str() { |
| 61 | #[cfg(feature = "Debug")] |
| 62 | "Debug" => Some(Self::Debug), |
| 63 | #[cfg(feature = "Clone")] |
| 64 | "Clone" => Some(Self::Clone), |
| 65 | #[cfg(feature = "Copy")] |
| 66 | "Copy" => Some(Self::Copy), |
| 67 | #[cfg(feature = "PartialEq")] |
| 68 | "PartialEq" => Some(Self::PartialEq), |
| 69 | #[cfg(feature = "Eq")] |
| 70 | "Eq" => Some(Self::Eq), |
| 71 | #[cfg(feature = "PartialOrd")] |
| 72 | "PartialOrd" => Some(Self::PartialOrd), |
| 73 | #[cfg(feature = "Ord")] |
| 74 | "Ord" => Some(Self::Ord), |
| 75 | #[cfg(feature = "Hash")] |
| 76 | "Hash" => Some(Self::Hash), |
| 77 | #[cfg(feature = "Default")] |
| 78 | "Default" => Some(Self::Default), |
| 79 | #[cfg(feature = "Deref")] |
| 80 | "Deref" => Some(Self::Deref), |
| 81 | #[cfg(feature = "DerefMut")] |
| 82 | "DerefMut" => Some(Self::DerefMut), |
| 83 | #[cfg(feature = "Into")] |
| 84 | "Into" => Some(Self::Into), |
| 85 | _ => None, |
| 86 | } |
| 87 | } |
| 88 | } |