1 +case_style.rs - source \ No newline at end of file diff --git a/src/strum_macros/helpers/metadata.rs.html b/src/strum_macros/helpers/metadata.rs.html index d0f53a87bb2d..860ed2ec6f08 100644 --- a/src/strum_macros/helpers/metadata.rs.html +++ b/src/strum_macros/helpers/metadata.rs.html @@ -1,4 +1,4 @@ - use heck::{ - ToKebabCase, ToLowerCamelCase, ToShoutySnakeCase, ToSnakeCase, ToTitleCase, ToUpperCamelCase, ToTrainCase, + ToKebabCase, ToLowerCamelCase, ToShoutySnakeCase, ToSnakeCase, ToTitleCase, ToUpperCamelCase, }; use std::str::FromStr; use syn::{ @@ -142,7 +137,6 @@ LowerCase, ScreamingKebabCase, PascalCase, - TrainCase, } const VALID_CASE_STYLES: &[&str] = &[ @@ -156,7 +150,6 @@ "UPPERCASE", "title_case", "mixed_case", - "Train-Case", ]; impl Parse for CaseStyle { @@ -193,7 +186,6 @@ "mixed_case" => CaseStyle::MixedCase, "lowercase" => CaseStyle::LowerCase, "UPPERCASE" => CaseStyle::UpperCase, - "Train-Case" => CaseStyle::TrainCase, _ => return Err(()), }) } @@ -217,7 +209,6 @@ CaseStyle::UpperCase => ident_string.to_uppercase(), CaseStyle::LowerCase => ident_string.to_lowercase(), CaseStyle::ScreamingKebabCase => ident_string.to_kebab_case().to_uppercase(), - CaseStyle::TrainCase => ident_string.to_train_case(), CaseStyle::CamelCase => { let camel_case = ident_string.to_upper_camel_case(); let mut pascal = String::with_capacity(camel_case.len()); @@ -240,6 +231,5 @@ let id = Ident::new("test_me", proc_macro2::Span::call_site()); assert_eq!("testMe", id.convert_case(Some(CaseStyle::CamelCase))); assert_eq!("TestMe", id.convert_case(Some(CaseStyle::PascalCase))); - assert_eq!("Test-Me", id.convert_case(Some(CaseStyle::TrainCase))); }
metadata.rs - source 1 +metadata.rs - source use proc_macro2::TokenStream; +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +
use proc_macro2::{Span, TokenStream}; use syn::{ parenthesized, parse::{Parse, ParseStream}, parse2, parse_str, punctuated::Punctuated, - Attribute, DeriveInput, Expr, ExprLit, Ident, Lit, LitBool, LitStr, Meta, MetaNameValue, Path, - Token, Variant, Visibility, + spanned::Spanned, + Attribute, DeriveInput, Ident, Lit, LitBool, LitStr, Meta, MetaNameValue, Path, Token, Variant, + Visibility, }; use super::case_style::CaseStyle; @@ -351,6 +385,17 @@ } } +impl Spanned for EnumMeta { + fn span(&self) -> Span { + match self { + EnumMeta::SerializeAll { kw, .. } => kw.span(), + EnumMeta::AsciiCaseInsensitive(kw) => kw.span(), + EnumMeta::Crate { kw, .. } => kw.span(), + EnumMeta::UsePhf(use_phf) => use_phf.span(), + } + } +} + pub enum EnumDiscriminantsMeta { Derive { kw: kw::derive, paths: Vec<Path> }, Name { kw: kw::name, name: Ident }, @@ -364,7 +409,7 @@ let kw = input.parse()?; let content; parenthesized!(content in input); - let paths = content.parse_terminated(Path::parse, Token![,])?; + let paths = content.parse_terminated::<_, Token![,]>(Path::parse)?; Ok(EnumDiscriminantsMeta::Derive { kw, paths: paths.into_iter().collect(), @@ -391,6 +436,17 @@ } } +impl Spanned for EnumDiscriminantsMeta { + fn span(&self) -> Span { + match self { + EnumDiscriminantsMeta::Derive { kw, .. } => kw.span, + EnumDiscriminantsMeta::Name { kw, .. } => kw.span, + EnumDiscriminantsMeta::Vis { kw, .. } => kw.span, + EnumDiscriminantsMeta::Other { path, .. } => path.span(), + } + } +} + pub trait DeriveInputExt { /// Get all the strum metadata associated with an enum. fn get_metadata(&self) -> syn::Result<Vec<EnumMeta>>; @@ -481,7 +537,7 @@ let kw = input.parse()?; let content; parenthesized!(content in input); - let props = content.parse_terminated(Prop::parse, Token![,])?; + let props = content.parse_terminated::<_, Token![,]>(Prop::parse)?; Ok(VariantMeta::Props { kw, props: props @@ -509,6 +565,22 @@ } } +impl Spanned for VariantMeta { + fn span(&self) -> Span { + match self { + VariantMeta::Message { kw, .. } => kw.span, + VariantMeta::DetailedMessage { kw, .. } => kw.span, + VariantMeta::Documentation { value } => value.span(), + VariantMeta::Serialize { kw, .. } => kw.span, + VariantMeta::ToString { kw, .. } => kw.span, + VariantMeta::Disabled(kw) => kw.span, + VariantMeta::Default(kw) => kw.span, + VariantMeta::AsciiCaseInsensitive { kw, .. } => kw.span, + VariantMeta::Props { kw, .. } => kw.span, + } + } +} + pub trait VariantExt { /// Get all the metadata associated with an enum variant. fn get_metadata(&self) -> syn::Result<Vec<VariantMeta>>; @@ -519,32 +591,26 @@ let result = get_metadata_inner("strum", &self.attrs)?; self.attrs .iter() - .filter(|attr| attr.path().is_ident("doc")) + .filter(|attr| attr.path.is_ident("doc")) .try_fold(result, |mut vec, attr| { if let Meta::NameValue(MetaNameValue { - value: - Expr::Lit(ExprLit { - lit: Lit::Str(value), - .. - }), + lit: Lit::Str(value), .. - }) = &attr.meta - { - vec.push(VariantMeta::Documentation { - value: value.clone(), - }) + }) = attr.parse_meta()? + { + vec.push(VariantMeta::Documentation { value }) } Ok(vec) }) } } -fn get_metadata_inner<'a, T: Parse>( +fn get_metadata_inner<'a, T: Parse + Spanned>( ident: &str, it: impl IntoIterator<Item = &'a Attribute>, ) -> syn::Result<Vec<T>> { it.into_iter() - .filter(|attr| attr.path().is_ident(ident)) + .filter(|attr| attr.path.is_ident(ident)) .try_fold(Vec::new(), |mut vec, attr| { vec.extend(attr.parse_args_with(Punctuated::<T, Token![,]>::parse_terminated)?); Ok(vec) diff --git a/src/strum_macros/helpers/mod.rs.html b/src/strum_macros/helpers/mod.rs.html index ebfa92f7acad..4d9cd537000f 100644 --- a/src/strum_macros/helpers/mod.rs.html +++ b/src/strum_macros/helpers/mod.rs.html @@ -1,4 +1,4 @@ -
mod.rs - source 1 +mod.rs - source 1 2 3 4 diff --git a/src/strum_macros/helpers/type_props.rs.html b/src/strum_macros/helpers/type_props.rs.html index 968b9b5c6b31..6ad9abeadc45 100644 --- a/src/strum_macros/helpers/type_props.rs.html +++ b/src/strum_macros/helpers/type_props.rs.html @@ -1,4 +1,4 @@ -type_props.rs - source 1 +type_props.rs - source 1 2 3 4 diff --git a/src/strum_macros/helpers/variant_props.rs.html b/src/strum_macros/helpers/variant_props.rs.html index 1d57e2e6592f..5065b35c89a6 100644 --- a/src/strum_macros/helpers/variant_props.rs.html +++ b/src/strum_macros/helpers/variant_props.rs.html @@ -1,4 +1,4 @@ -variant_props.rs - source 1 +variant_props.rs - source 1 2 3 4 @@ -152,7 +152,7 @@ pub documentation: Vec<LitStr>, pub string_props: Vec<(LitStr, LitStr)>, serialize: Vec<LitStr>, - pub to_string: Option<LitStr>, + to_string: Option<LitStr>, ident: Option<Ident>, } diff --git a/src/strum_macros/lib.rs.html b/src/strum_macros/lib.rs.html index aef9ba8bd21f..30e89015eb94 100644 --- a/src/strum_macros/lib.rs.html +++ b/src/strum_macros/lib.rs.html @@ -1,4 +1,4 @@ -lib.rs - source 1 +lib.rs - source 1 2 3 4 @@ -753,31 +753,6 @@ 753 754 755 -756 -757 -758 -759 -760 -761 -762 -763 -764 -765 -766 -767 -768 -769 -770 -771 -772 -773 -774 -775 -776 -777 -778 -779 -780//! # Strum //! //! Strum is a set of macros and traits for working with @@ -955,7 +930,7 @@ /// use strum::VariantNames; /// /// #[derive(Debug, EnumString, EnumVariantNames)] -/// #[strum(serialize_all = "kebab-case")] +/// #[strum(serialize_all = "kebab_case")] /// enum Color { /// Red, /// Blue, @@ -1033,7 +1008,7 @@ toks.into() } -/// implements `std::string::ToString` on an enum +/// implements `std::string::ToString` on en enum /// /// ``` /// // You need to bring the ToString trait into scope to use it @@ -1124,7 +1099,7 @@ /// Creates a new type that iterates of the variants of an enum. /// /// Iterate over the variants of an Enum. Any additional data on your variants will be set to `Default::default()`. -/// The macro implements `strum::IntoEnumIterator` on your enum and creates a new type called `YourEnumIter` that is the iterator object. +/// The macro implements `strum::IntoEnumIter` on your enum and creates a new type called `YourEnumIter` that is the iterator object. /// You cannot derive `EnumIter` on any type with a lifetime bound (`<'a>`) because the iterator would surely /// create [unbounded lifetimes](https://doc.rust-lang.org/nightly/nomicon/unbounded-lifetimes.html). /// @@ -1164,38 +1139,13 @@ toks.into() } -/// Generated `is_*()` methods for each variant. -/// E.g. `Color.is_red()`. -/// -/// ``` -/// -/// use strum_macros::EnumIs; -/// -/// #[derive(EnumIs, Debug)] -/// enum Color { -/// Red, -/// Green { range: usize }, -/// } -/// -/// assert!(Color::Red.is_red()); -/// assert!(Color::Green{range: 0}.is_green()); -/// ``` -#[proc_macro_derive(EnumIs, attributes(strum))] -pub fn enum_is(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let ast = syn::parse_macro_input!(input as DeriveInput); - - let toks = macros::enum_is::enum_is_inner(&ast).unwrap_or_else(|err| err.to_compile_error()); - debug_print_generated(&ast, &toks); - toks.into() -} - /// Add a function to enum that allows accessing variants by its discriminant /// /// This macro adds a standalone function to obtain an enum variant by its discriminant. The macro adds /// `from_repr(discriminant: usize) -> Option<YourEnum>` as a standalone function on the enum. For /// variants with additional data, the returned variant will use the `Default` trait to fill the /// data. The discriminant follows the same rules as `rustc`. The first discriminant is zero and each -/// successive variant has a discriminant of one greater than the previous variant, except where an +/// successive variant has a discriminant of one greater than the previous variant, expect where an /// explicit discriminant is specified. The type of the discriminant will match the `repr` type if /// it is specifed. /// diff --git a/src/strum_macros/macros/enum_count.rs.html b/src/strum_macros/macros/enum_count.rs.html index 0c9b9e7797b1..919cb72526f5 100644 --- a/src/strum_macros/macros/enum_count.rs.html +++ b/src/strum_macros/macros/enum_count.rs.html @@ -1,4 +1,4 @@ -
enum_count.rs - source 1 +enum_count.rs - source use proc_macro2::TokenStream; use quote::quote; use syn::{Data, DeriveInput}; -use crate::helpers::variant_props::HasStrumVariantProperties; use crate::helpers::{non_enum_error, HasTypeProperties}; pub(crate) fn enum_count_inner(ast: &DeriveInput) -> syn::Result<TokenStream> { let n = match &ast.data { - Data::Enum(v) => v.variants.iter().try_fold(0usize, |acc, v| { - if v.get_variant_properties()?.disabled.is_none() { - Ok::<usize, syn::Error>(acc + 1usize) - } else { - Ok::<usize, syn::Error>(acc) - } - })?, + Data::Enum(v) => v.variants.len(), _ => return Err(non_enum_error()), }; let type_properties = ast.get_type_properties()?; diff --git a/src/strum_macros/macros/enum_discriminants.rs.html b/src/strum_macros/macros/enum_discriminants.rs.html index ec2deb2b4b8d..bcca16e2e09c 100644 --- a/src/strum_macros/macros/enum_discriminants.rs.html +++ b/src/strum_macros/macros/enum_discriminants.rs.html @@ -1,4 +1,4 @@ -
enum_discriminants.rs - source 1 +enum_discriminants.rs - source use proc_macro2::{Span, TokenStream, TokenTree}; use quote::{quote, ToTokens}; use syn::parse_quote; @@ -217,16 +215,14 @@ .filter(|attr| { ATTRIBUTES_TO_COPY .iter() - .any(|attr_whitelisted| attr.path().is_ident(attr_whitelisted)) + .any(|attr_whitelisted| attr.path.is_ident(attr_whitelisted)) }) .map(|attr| { - if attr.path().is_ident("strum_discriminants") { - let mut ts = attr.meta.require_list()?.to_token_stream().into_iter(); - - // Discard strum_discriminants(...) - let _ = ts.next(); - - let passthrough_group = ts + if attr.path.is_ident("strum_discriminants") { + let passthrough_group = attr + .tokens + .clone() + .into_iter() .next() .ok_or_else(|| strum_discriminants_passthrough_error(attr))?; let passthrough_attribute = match passthrough_group { diff --git a/src/strum_macros/macros/enum_is.rs.html b/src/strum_macros/macros/enum_is.rs.html deleted file mode 100644 index 06647a51b67a..000000000000 --- a/src/strum_macros/macros/enum_is.rs.html +++ /dev/null @@ -1,123 +0,0 @@ -
enum_is.rs - source \ No newline at end of file diff --git a/src/strum_macros/macros/enum_iter.rs.html b/src/strum_macros/macros/enum_iter.rs.html index 6c5d996396dc..22b7065ba0d2 100644 --- a/src/strum_macros/macros/enum_iter.rs.html +++ b/src/strum_macros/macros/enum_iter.rs.html @@ -1,4 +1,4 @@ - 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 -use crate::helpers::{non_enum_error, HasStrumVariantProperties}; -use heck::ToSnakeCase; -use proc_macro2::TokenStream; -use quote::{format_ident, quote}; -use syn::{Data, DeriveInput}; - -pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result<TokenStream> { - let variants = match &ast.data { - Data::Enum(v) => &v.variants, - _ => return Err(non_enum_error()), - }; - - let enum_name = &ast.ident; - - let variants: Vec<_> = variants - .iter() - .filter_map(|variant| { - if variant.get_variant_properties().ok()?.disabled.is_some() { - return None; - } - - let variant_name = &variant.ident; - let fn_name = format_ident!("is_{}", snakify(&variant_name.to_string())); - - Some(quote! { - #[must_use] - #[inline] - pub const fn #fn_name(&self) -> bool { - match self { - &#enum_name::#variant_name { .. } => true, - _ => false - } - } - }) - }) - .collect(); - - Ok(quote! { - impl #enum_name { - #(#variants)* - } - } - .into()) -} - -/// heck doesn't treat numbers as new words, but this function does. -/// E.g. for input `Hello2You`, heck would output `hello2_you`, and snakify would output `hello_2_you`. -fn snakify(s: &str) -> String { - let mut output: Vec<char> = s.to_string().to_snake_case().chars().collect(); - let mut num_starts = vec![]; - for (pos, c) in output.iter().enumerate() { - if c.is_digit(10) && pos != 0 && !output[pos - 1].is_digit(10) { - num_starts.push(pos); - } - } - // need to do in reverse, because after inserting, all chars after the point of insertion are off - for i in num_starts.into_iter().rev() { - output.insert(i, '_') - } - output.into_iter().collect() -} -
enum_iter.rs - source 1 +enum_iter.rs - source 1 2 3 4 @@ -156,20 +156,6 @@ 156 157 158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::{Data, DeriveInput, Fields, Ident}; @@ -183,7 +169,6 @@ let vis = &ast.vis; let type_properties = ast.get_type_properties()?; let strum_module_path = type_properties.crate_module_path(); - let doc_comment = format!("An iterator over the variants of [{}]", name); if gen.lifetimes().count() > 0 { return Err(syn::Error::new( @@ -237,14 +222,11 @@ arms.push(quote! { _ => ::core::option::Option::None }); let iter_name = syn::parse_str::<Ident>(&format!("{}Iter", name)).unwrap(); - // Create a string literal "MyEnumIter" to use in the debug impl. - let iter_name_debug_struct = - syn::parse_str::<syn::LitStr>(&format!("\"{}\"", iter_name)).unwrap(); - Ok(quote! { - #[doc = #doc_comment] + #[doc = "An iterator over the variants of [Self]"] #[allow( missing_copy_implementations, + missing_debug_implementations, )] #vis struct #iter_name #ty_generics { idx: usize, @@ -252,16 +234,6 @@ marker: ::core::marker::PhantomData #phantom_data, } - impl #impl_generics core::fmt::Debug for #iter_name #ty_generics #where_clause { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - // We don't know if the variants implement debug themselves so the only thing we - // can really show is how many elements are left. - f.debug_struct(#iter_name_debug_struct) - .field("len", &self.len()) - .finish() - } - } - impl #impl_generics #iter_name #ty_generics #where_clause { fn get(&self, idx: usize) -> Option<#name #ty_generics> { match idx { diff --git a/src/strum_macros/macros/enum_messages.rs.html b/src/strum_macros/macros/enum_messages.rs.html index 3a766ea6d827..5d500793ae82 100644 --- a/src/strum_macros/macros/enum_messages.rs.html +++ b/src/strum_macros/macros/enum_messages.rs.html @@ -1,4 +1,4 @@ -
enum_messages.rs - source 1 +enum_messages.rs - source 1 2 3 4 diff --git a/src/strum_macros/macros/enum_properties.rs.html b/src/strum_macros/macros/enum_properties.rs.html index 0a1005e82c64..05e79b3eaf82 100644 --- a/src/strum_macros/macros/enum_properties.rs.html +++ b/src/strum_macros/macros/enum_properties.rs.html @@ -1,4 +1,4 @@ -enum_properties.rs - source 1 +enum_properties.rs - source 1 2 3 4 diff --git a/src/strum_macros/macros/enum_variant_names.rs.html b/src/strum_macros/macros/enum_variant_names.rs.html index bf1ed3414a97..6cd32a64ab21 100644 --- a/src/strum_macros/macros/enum_variant_names.rs.html +++ b/src/strum_macros/macros/enum_variant_names.rs.html @@ -1,4 +1,4 @@ -enum_variant_names.rs - source 1 +enum_variant_names.rs - source 1 2 3 4 diff --git a/src/strum_macros/macros/from_repr.rs.html b/src/strum_macros/macros/from_repr.rs.html index eec610170c7d..0e4df9648e06 100644 --- a/src/strum_macros/macros/from_repr.rs.html +++ b/src/strum_macros/macros/from_repr.rs.html @@ -1,4 +1,4 @@ -from_repr.rs - source 1 +from_repr.rs - source 1 2 3 4 @@ -137,22 +137,9 @@ 137 138 139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152use heck::ToShoutySnakeCase; use proc_macro2::{Span, TokenStream}; -use quote::{format_ident, quote, ToTokens}; +use quote::{format_ident, quote}; use syn::{Data, DeriveInput, Fields, PathArguments, Type, TypeParen}; use crate::helpers::{non_enum_error, HasStrumVariantProperties}; @@ -166,21 +153,8 @@ let mut discriminant_type: Type = syn::parse("usize".parse().unwrap()).unwrap(); for attr in attrs { - let path = attr.path(); - - let mut ts = if let Ok(ts) = attr - .meta - .require_list() - .map(|metas| metas.to_token_stream().into_iter()) - { - ts - } else { - continue; - }; - // Discard the path - let _ = ts.next(); - let tokens: TokenStream = ts.collect(); - + let path = &attr.path; + let tokens = &attr.tokens; if path.leading_colon.is_some() { continue; } diff --git a/src/strum_macros/macros/mod.rs.html b/src/strum_macros/macros/mod.rs.html index b83f2fbf7e7f..596a5baa469d 100644 --- a/src/strum_macros/macros/mod.rs.html +++ b/src/strum_macros/macros/mod.rs.html @@ -1,4 +1,4 @@ -
mod.rs - source 1 +mod.rs - source pub mod enum_count; pub mod enum_discriminants; -pub mod enum_is; pub mod enum_iter; pub mod enum_messages; pub mod enum_properties; diff --git a/src/strum_macros/macros/strings/as_ref_str.rs.html b/src/strum_macros/macros/strings/as_ref_str.rs.html index 84688f98fb98..4fe482a28ce3 100644 --- a/src/strum_macros/macros/strings/as_ref_str.rs.html +++ b/src/strum_macros/macros/strings/as_ref_str.rs.html @@ -1,4 +1,4 @@ -
as_ref_str.rs - source 1 +as_ref_str.rs - source 1 2 3 4 @@ -197,7 +197,7 @@ let mut generics = ast.generics.clone(); generics .params - .push(syn::GenericParam::Lifetime(syn::LifetimeParam::new( + .push(syn::GenericParam::Lifetime(syn::LifetimeDef::new( parse_quote!('_derivative_strum), ))); let (impl_generics2, _, _) = generics.split_for_impl(); diff --git a/src/strum_macros/macros/strings/display.rs.html b/src/strum_macros/macros/strings/display.rs.html index 16340339c3df..61852cd65580 100644 --- a/src/strum_macros/macros/strings/display.rs.html +++ b/src/strum_macros/macros/strings/display.rs.html @@ -1,4 +1,4 @@ -display.rs - source 1 +display.rs - source use proc_macro2::TokenStream; use quote::quote; use syn::{Data, DeriveInput, Fields}; @@ -97,21 +83,7 @@ Fields::Named(..) => quote! { {..} }, }; - if variant_properties.to_string.is_none() && variant_properties.default.is_some() { - match &variant.fields { - Fields::Unnamed(fields) if fields.unnamed.len() == 1 => { - arms.push(quote! { #name::#ident(ref s) => f.pad(s) }); - } - _ => { - return Err(syn::Error::new_spanned( - variant, - "Default only works on newtype structs with a single String field", - )) - } - } - } else { - arms.push(quote! { #name::#ident #params => f.pad(#output) }); - } + arms.push(quote! { #name::#ident #params => f.pad(#output) }); } if arms.len() < variants.len() { diff --git a/src/strum_macros/macros/strings/from_string.rs.html b/src/strum_macros/macros/strings/from_string.rs.html index cd9fbbe88df5..9159de34c680 100644 --- a/src/strum_macros/macros/strings/from_string.rs.html +++ b/src/strum_macros/macros/strings/from_string.rs.html @@ -1,4 +1,4 @@ -
from_string.rs - source 1 +from_string.rs - source 1 2 3 4 diff --git a/src/strum_macros/macros/strings/mod.rs.html b/src/strum_macros/macros/strings/mod.rs.html index 3a8c19b700ff..7662fc9ebd5c 100644 --- a/src/strum_macros/macros/strings/mod.rs.html +++ b/src/strum_macros/macros/strings/mod.rs.html @@ -1,4 +1,4 @@ -mod.rs - source 1 +mod.rs - source 1 2 3 4 diff --git a/src/strum_macros/macros/strings/to_string.rs.html b/src/strum_macros/macros/strings/to_string.rs.html index da9d4cff44e6..e498b78044ab 100644 --- a/src/strum_macros/macros/strings/to_string.rs.html +++ b/src/strum_macros/macros/strings/to_string.rs.html @@ -1,4 +1,4 @@ -to_string.rs - source 1 +to_string.rs - source use proc_macro2::TokenStream; use quote::quote; use syn::{Data, DeriveInput, Fields}; @@ -89,22 +73,6 @@ continue; } - // display variants like Green("lime") as "lime" - if variant_properties.to_string.is_none() && variant_properties.default.is_some() { - match &variant.fields { - Fields::Unnamed(fields) if fields.unnamed.len() == 1 => { - arms.push(quote! { #name::#ident(ref s) => ::std::string::String::from(s) }); - continue; - } - _ => { - return Err(syn::Error::new_spanned( - variant, - "Default only works on newtype structs with a single String field", - )) - } - } - } - // Look at all the serialize attributes. let output = variant_properties.get_preferred_name(type_properties.case_style); diff --git a/strum_macros/all.html b/strum_macros/all.html index 1807d0109a49..54c0c0feef7c 100644 --- a/strum_macros/all.html +++ b/strum_macros/all.html @@ -1 +1 @@ -
List of all items in this crate \ No newline at end of file + List of all items in this crate \ No newline at end of file diff --git a/strum_macros/derive.EnumCount.html b/strum_macros/derive.EnumCount.html index 067bca9c5e33..735c2dc7ac04 100644 --- a/strum_macros/derive.EnumCount.html +++ b/strum_macros/derive.EnumCount.html @@ -1,4 +1,4 @@ - EnumCount in strum_macros - Rust Derive Macro strum_macros::
source ·EnumCount #[derive(EnumCount)] +
EnumCount in strum_macros - Rust Derive Macro strum_macros::
source ·EnumCount #[derive(EnumCount)] { // Attributes available to this derive: #[strum] diff --git a/strum_macros/derive.EnumDiscriminants.html b/strum_macros/derive.EnumDiscriminants.html index 3e15296d6e18..ae01ad32bf7c 100644 --- a/strum_macros/derive.EnumDiscriminants.html +++ b/strum_macros/derive.EnumDiscriminants.html @@ -1,4 +1,4 @@ -
EnumDiscriminants in strum_macros - Rust Derive Macro strum_macros::
source ·EnumDiscriminants #[derive(EnumDiscriminants)] +
EnumDiscriminants in strum_macros - Rust Derive Macro strum_macros::
source ·EnumDiscriminants #[derive(EnumDiscriminants)] { // Attributes available to this derive: #[strum] diff --git a/strum_macros/derive.EnumIs.html b/strum_macros/derive.EnumIs.html deleted file mode 100644 index da984a88d84b..000000000000 --- a/strum_macros/derive.EnumIs.html +++ /dev/null @@ -1,20 +0,0 @@ -
EnumIs in strum_macros - Rust \ No newline at end of file diff --git a/strum_macros/derive.EnumIter.html b/strum_macros/derive.EnumIter.html index 1cc36dcf4a66..bd37cf492d18 100644 --- a/strum_macros/derive.EnumIter.html +++ b/strum_macros/derive.EnumIter.html @@ -5,7 +5,7 @@ } Derive Macro strum_macros::
source ·EnumIs #[derive(EnumIs)] -{ - // Attributes available to this derive: - #[strum] -} -
Expand description
Generated
- -is_*()
methods for each variant. -E.g.Color.is_red()
.--use strum_macros::EnumIs; - -#[derive(EnumIs, Debug)] -enum Color { - Red, - Green { range: usize }, -} - -assert!(Color::Red.is_red()); -assert!(Color::Green{range: 0}.is_green());
Expand description
Creates a new type that iterates of the variants of an enum.
Iterate over the variants of an Enum. Any additional data on your variants will be set to
diff --git a/strum_macros/derive.EnumMessage.html b/strum_macros/derive.EnumMessage.html index 2548e00b3d2f..d930fb7b19bd 100644 --- a/strum_macros/derive.EnumMessage.html +++ b/strum_macros/derive.EnumMessage.html @@ -1,4 +1,4 @@ -Default::default()
. -The macro implementsstrum::IntoEnumIterator
on your enum and creates a new type calledYourEnumIter
that is the iterator object. +The macro implementsstrum::IntoEnumIter
on your enum and creates a new type calledYourEnumIter
that is the iterator object. You cannot deriveEnumIter
on any type with a lifetime bound (<'a>
) because the iterator would surely create unbounded lifetimes.EnumMessage in strum_macros - Rust Derive Macro strum_macros::
source ·EnumMessage #[derive(EnumMessage)] +
EnumMessage in strum_macros - Rust Derive Macro strum_macros::
source ·EnumMessage #[derive(EnumMessage)] { // Attributes available to this derive: #[strum] diff --git a/strum_macros/derive.EnumProperty.html b/strum_macros/derive.EnumProperty.html index 813b050df7d1..5b902ac6d749 100644 --- a/strum_macros/derive.EnumProperty.html +++ b/strum_macros/derive.EnumProperty.html @@ -1,4 +1,4 @@ -
EnumProperty in strum_macros - Rust Derive Macro strum_macros::
source ·EnumProperty #[derive(EnumProperty)] +
EnumProperty in strum_macros - Rust Derive Macro strum_macros::
source ·EnumProperty #[derive(EnumProperty)] { // Attributes available to this derive: #[strum] diff --git a/strum_macros/derive.EnumVariantNames.html b/strum_macros/derive.EnumVariantNames.html index 1090035e0245..7c40929a0057 100644 --- a/strum_macros/derive.EnumVariantNames.html +++ b/strum_macros/derive.EnumVariantNames.html @@ -13,7 +13,7 @@ use strum::VariantNames; #[derive(Debug, EnumString, EnumVariantNames)] -#[strum(serialize_all = "kebab-case")] +#[strum(serialize_all = "kebab_case")] enum Color { Red, Blue, diff --git a/strum_macros/derive.FromRepr.html b/strum_macros/derive.FromRepr.html index 8b9967b3d735..4fda68844733 100644 --- a/strum_macros/derive.FromRepr.html +++ b/strum_macros/derive.FromRepr.html @@ -1,4 +1,4 @@ -
FromRepr in strum_macros - Rust Derive Macro strum_macros::
FromRepr