1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "alloc")]
extern crate alloc;
/// Adds an function `all` to enum, returning an array with all variants of the enum
///
/// ```rust
/// use fieldless_enum_tools::All;
///
/// #[derive(All, Debug, PartialEq, Eq)]
/// enum CoolEnum {
/// CoolVariantOne,
/// CoolVariantTwo
/// }
///
/// assert_eq!(
/// CoolEnum::all(),
/// [CoolEnum::CoolVariantOne, CoolEnum::CoolVariantTwo]
/// );
/// ```
///
/// # Attributes
///
/// ## Outer attributes
///
/// `#[all_doc = r#"..."#)]`
///
/// Sets the doc of the function, with the default being "Returns an array of all elements on this enum."
pub use fieldless_enum_tools_impl::All;
/// Implements [`Not`] for enum.
///
/// ```rust
/// use fieldless_enum_tools::Not;
///
/// // works without any attributes on enum with up to two variants
/// #[derive(Not, Debug, PartialEq, Eq)]
/// enum One {
/// One
/// }
///
/// assert_eq!(!One::One, One::One);
///
/// #[derive(Not, Debug, PartialEq, Eq)]
/// enum More {
/// One,
/// Two
/// }
///
/// assert_eq!(!More::One, More::Two);
/// assert_eq!(!More::Two, More::One);
///
/// // requires attributes after
/// #[derive(Not, Debug, PartialEq, Eq)]
/// enum Multiple {
/// #[not(OppositeOfOne)]
/// One,
/// #[not(OppositeOfTwo)]
/// Two,
/// #[not(One)]
/// OppositeOfOne,
/// #[not(Two)]
/// OppositeOfTwo,
/// #[not(Trap)]
/// Trap
/// }
///
/// assert_eq!(!Multiple::One, Multiple::OppositeOfOne);
/// assert_eq!(!Multiple::OppositeOfTwo, Multiple::Two);
/// assert_eq!(!Multiple::Trap, Multiple::Trap);
/// ```
///
/// # Attributes
///
/// ## Variant attributes
///
/// `#[not(...)]`
///
/// Specifies which variant this variant will return when [`Not`]'ed
///
/// [`Not`]: `core::ops::Not`
pub use fieldless_enum_tools_impl::Not;
/// Implements
/// [`AsRef<str>`],
/// [`Into<String>`][^alloc],
/// [`Display`] (therefore [`ToString`][^alloc]), [`FromStr`],
/// [`TryFrom<String>`][^alloc],
/// [`Serialize`][^serde] and [`Deserialize`][^serde] for enum.
///
///```rust
/// use fieldless_enum_tools::FromToStr;
///
/// #[derive(FromToStr, Debug, PartialEq, Eq, Clone, Copy)]
/// #[fromtostr(format(style = "delimited", separator = "😎"))]
/// enum CoolEnum {
/// #[fromtostr(aliases("cool_variant_one"))]
/// CoolVariantOne,
/// #[fromtostr(rename("Very😎Cool😎Variant😎Two"))]
/// CoolVariantTwo
/// }
///
///
/// let cool = CoolEnum::CoolVariantOne;
///
/// assert_eq!(cool.as_ref(), "Cool😎Variant😎One");
/// assert_eq!("cool_variant_one".parse(), Ok(cool));
/// assert_eq!("Cool😎Variant😎One".parse(), Ok(cool));
///
/// let cool = CoolEnum::CoolVariantTwo;
/// assert_eq!("Very😎Cool😎Variant😎Two".parse(), Ok(cool));
///
/// assert_eq!("uncool variant :(".parse::<CoolEnum>(), Err(()));
/// // errors because we renamed it to Very😎Cool😎Variant😎Two
/// assert_eq!("Cool😎Variant😎Two".parse::<CoolEnum>(), Err(()));
///```
///
/// # Attributes
/// ## Outer attributes
///
/// `#[fromtostr(skip(...*))]`
///
/// Skips implementing specified traits
///
/// **Possible Values**
///
/// >| Value | Skips |
/// >|-----------------|---------------------|
/// >| `TryFromString` | [`TryFrom<String>`] |
/// >| `FromStr` | [`FromStr`] |
/// >| `AsRefStr` | [`AsRef<str>`] |
/// >| `IntoString` | [`Into<String>`] |
/// >| `Display` | [`Display`] |
/// >| `Serialize` | [`Serialize`] |
/// >| `Deserialize` | [`Deserialize`] |
///
/// ---
///
/// `#[fromtostr(format(style = "...", separator = "..."?))]`
///
/// Format variants using specified [style](Self#possible-styles)
///
///
/// ## Variant attributes
///
/// `#[fromtostr(aliases("..."*))]`
///
/// Specifies one (or more aliases) for this variant
///
/// ---
///
/// `#[fromtostr(rename("..."))]` or `#[fromtostr(rename(style = "...", separator = "..."?))]`
///
/// Renames this variant with specified string or specified [format style](Self#possible-styles)
///
/// # Possible Styles
///
/// >| Style Name | Description | Example | Note |
/// >|-------------------|-------------------------------------------------------|-----------------------|---------------------------------------------------------|
/// >| `none` | keep it as is | `TwoWords` | |
/// >| `lower` | to lowercase | `twowords` | |
/// >| `UPPER` | to uppercase | `TWOWORDS` | |
/// >| `snake` | to snake case | `two_words` | alias to `delimitedlower` style with a `_` separator |
/// >| `kebab` | to kebab case | `two-words` | alias to `delimitedlower` style with a `-` separator |
/// >| `SCREAMING_SNAKE` | to screaming snake case | `TWO_WORDS` | alias to `DELIMITEDUPPER` with a `_` separator |
/// >| `SCREAMING-KEBAB` | to screaming kebab case | `TWO-WORDS` | alias it to `DELIMITEDUPPER` style with a `-` separator |
/// >| `camel` | to camel case | `twoWords` | |
/// >| `camel_Snake` | to camel snake case | `two_Words` | |
/// >| `Pascal` | to pascal case | `TwoWords` | |
/// >| `Pascal_Snake` | to pascal snake case | `Two_Words` | |
/// >| `Train` | to train case | `Two-Words` | |
/// >| `delimited` | delimits every word with separator | `Two{separator}Words` | needs to specify a separator value |
/// >| `delimitedlower` | delimits every word with separator, then to lowercase | `two{separator}words` | needs to specify a separator value |
/// >| `DELIMITEDUPPER` | delimits every word with separator, then to uppercase | `TWO{SEPARATOR}WORDS` | needs to specify a separator value |
///
/// [^alloc]: if crate feature `std` or `alloc` avaliable.
///
/// [^serde]: if crate feature `serde` avaliable.
///
/// [`Display`]: `core::fmt::Display`
/// [`TryFrom<String>`]: `core::convert::TryFrom`
/// [`FromStr`]: `core::str::FromStr`
/// [`Serialize`]: https://serde.rs/
/// [`Deserialize`]: https://serde.rs/
pub use fieldless_enum_tools_impl::FromToStr;
#[cfg(not(doc))]
pub mod __internal {
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::string::String;
#[cfg(feature = "std")]
pub use std::string::String;
#[cfg(feature = "serde")]
pub use serde;
#[cfg(not(feature = "serde"))]
#[macro_export]
macro_rules! if_serde_enabled {
($($t:tt)*) => {};
}
#[cfg(feature = "serde")]
#[macro_export]
macro_rules! if_serde_enabled {
($($t:tt)*) => { $($t)* };
}
#[cfg(not(any(feature = "alloc", feature = "std")))]
#[macro_export]
macro_rules! if_alloc_enabled {
($($t:tt)*) => {};
}
#[cfg(any(feature = "alloc", feature = "std"))]
#[macro_export]
macro_rules! if_alloc_enabled {
($($t:tt)*) => { $($t)* };
}
#[cfg(not(feature = "std"))]
#[macro_export]
macro_rules! if_std_enabled {
($($t:tt)*) => {};
}
#[cfg(feature = "std")]
#[macro_export]
macro_rules! if_std_enabled {
($($t:tt)*) => { $($t)* };
}
}