From 22606efa5005123e56e75ae7b1858d102d371439 Mon Sep 17 00:00:00 2001 From: Peter Glotfelty Date: Sat, 27 Jan 2024 17:06:15 -0800 Subject: [PATCH] Update Changelog etc in prep for release (#324) * Get files ready for release * More documentation. --------- Co-authored-by: Peter Glotfelty --- CHANGELOG.md | 76 ++++++++++++++++ README.md | 43 +++++----- strum/Cargo.toml | 4 +- strum/src/lib.rs | 22 ++--- strum_macros/Cargo.toml | 4 +- strum_macros/src/helpers/mod.rs | 2 +- strum_macros/src/lib.rs | 86 ++++++++++++++----- ...ariants_array.rs => enum_variant_array.rs} | 14 ++- strum_macros/src/macros/mod.rs | 4 +- strum_macros/src/macros/strings/display.rs | 2 +- strum_tests/tests/enum_is.rs | 6 +- strum_tests/tests/enum_iter.rs | 2 +- ...ariants_array.rs => enum_variant_array.rs} | 28 +++--- strum_tests/tests/enum_variant_names.rs | 14 +-- .../{enum_table.rs => enum_variant_table.rs} | 0 15 files changed, 211 insertions(+), 96 deletions(-) rename strum_macros/src/macros/{static_variants_array.rs => enum_variant_array.rs} (62%) rename strum_tests/tests/{static_variants_array.rs => enum_variant_array.rs} (69%) rename strum_tests/tests/{enum_table.rs => enum_variant_table.rs} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 993b9159..6d97da53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,81 @@ # Changelog +## 0.26.0 + +### Breaking Changes + +* The `EnumVariantNames` macro has been renamed `VariantNames`. The deprecation warning should steer you in + the right direction for fixing the warning. +* The Iterator struct generated by EnumIter now has new bounds on it. This shouldn't break code unless you manually + added the implementation in your code. +* `Display` now supports format strings using named fields in the enum variant. This should be a no-op for most code. + However, if you were outputting a string like `"Hello {field}"`, this will now be interpretted as a format string. + + +### New features + +* The `VariantArray` macro has been added. This macro adds an associated constant `VARIANTS` to your enum. The constant + is a `&'static [Self]` slice so that you can access all the variants of your enum. This only works on enums that only + have unit variants. + + ```rust + use strum::VariantArray; + + #[derive(Debug, VariantArray)] + enum Color { + Red, + Blue, + Green, + } + + fn main() { + println!("{:?}", Color::VARIANTS); // prints: ["Red", "Blue", "Green"] + } + ``` + +* The `EnumMap` macro has been *experimentally* added. This macro adds a new type that stores an item for each variant + of the enum. This is useful for storing a value for each variant of an enum. This is an experimental feature because + I'm not convinced the current api surface area is correct. + + ```rust + use strum::EnumMap; + + #[derive(Copy, Clone, Debug, EnumMap)] + enum Color { + Red, + Blue, + Green, + } + + fn main() { + let mut counts = ColorTable::filled(0); + for color in &[Color::Red, Color::Red, Color::Green]] { + counts[color] += 1; + } + + assert_eq!(counts[Color::Red], 2); + assert_eq!(counts[Color::Blue], 0); + assert_eq!(counts[Color::Green], 1); + } + ``` + +* `Display` has 2 new features: + * the `strum(prefix = "some_value")` attribute on an enum now allows you to prepend a string onto every + variant when you serialize it. + + * Custom `to_string` and `serialize` attributes now support string interopolation on serialization. + +### PR's Merged + +* [#322](https://github.com/Peternator7/strum/pull/322): avoid collisions on `std::fmt::Debug` +* [#321](https://github.com/Peternator7/strum/pull/321): avoid conflicts with consecutive underscores. +* [#314](https://github.com/Peternator7/strum/pull/314): add additional bounds to EnumIterator +* [#311](https://github.com/Peternator7/strum/pull/311): add FusedIterator bounds to EnumIterator +* [#297](https://github.com/Peternator7/strum/pull/297): New macro, add `VariantArray` +* [#296](https://github.com/Peternator7/strum/pull/296): adds prefix attribute to To/From String macros. +* [#294](https://github.com/Peternator7/strum/pull/294): use named enum fields in to_string macro. + + ## 0.25.3 (strum_macros) Received a number of bug fix PR's. diff --git a/README.md b/README.md index bf44c1d8..564488e1 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ Cargo.toml. Strum_macros contains the macros needed to derive all the traits in ```toml [dependencies] -strum = "0.25" -strum_macros = "0.25" +strum = "0.26" +strum_macros = "0.26" # You can also use the "derive" feature, and import the macros directly from "strum" -# strum = { version = "0.25", features = ["derive"] } +# strum = { version = "0.26", features = ["derive"] } ``` # Strum Macros @@ -40,18 +40,21 @@ Strum has implemented the following macros: | [FromRepr] | Convert from an integer to an enum. | | [AsRefStr] | Implement `AsRef` for `MyEnum` | | [IntoStaticStr] | Implements `From for &'static str` on an enum | -| [EnumVariantNames] | Adds an associated `VARIANTS` constant which is an array of discriminant names | | [EnumIter] | Creates a new type that iterates of the variants of an enum. | -| [EnumMap] | Creates a new type that stores an item of a specified type for each variant of the enum. | | [EnumProperty] | Add custom properties to enum variants. | | [EnumMessage] | Add a verbose message to an enum variant. | | [EnumDiscriminants] | Generate a new type with only the discriminant names. | | [EnumCount] | Add a constant `usize` equal to the number of variants. | -| [StaticVariantsArray] | Adds an associated `ALL_VARIANTS` constant which is an array of all enum discriminants | +| [VariantArray] | Adds an associated `VARIANTS` constant which is an array of all enum discriminants | +| [VariantNames] | Adds an associated `VARIANTS` constant which is an array of discriminant names | +| [EnumTable] | *Experimental*, creates a new type that stores an item of a specified type for each variant of the enum. | # Contributing -Thanks for your interest in contributing. The project is divided into 3 parts, the traits are in the +Thanks for your interest in contributing. Bug fixes are always welcome. If you are interested in implementing or +adding a macro, please open an issue first to discuss the feature. I have limited bandwidth to review new features. + +The project is divided into 3 parts, the traits are in the `/strum` folder. The procedural macros are in the `/strum_macros` folder, and the integration tests are in `/strum_tests`. If you are adding additional features to `strum` or `strum_macros`, you should make sure to run the tests and add new integration tests to make sure the features work as expected. @@ -69,17 +72,17 @@ information through strings. Strumming is also a very whimsical motion, much like writing Rust code. -[Macro-Renames]: https://github.com/Peternator7/strum/wiki/Macro-Renames [EnumString]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumString.html -[Display]: https://docs.rs/strum_macros/0.25/strum_macros/derive.Display.html -[AsRefStr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.AsRefStr.html -[IntoStaticStr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.IntoStaticStr.html -[EnumVariantNames]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumVariantNames.html -[EnumIter]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumIter.html -[EnumIs]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumIs.html -[EnumProperty]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumProperty.html -[EnumMessage]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumMessage.html -[EnumDiscriminants]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumDiscriminants.html -[EnumCount]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumCount.html -[FromRepr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.FromRepr.html -[StaticVariantsArray]: https://docs.rs/strum_macros/0.25/strum_macros/derive.StaticVariantsArray.html +[Display]: https://docs.rs/strum_macros/latest/strum_macros/derive.Display.html +[AsRefStr]: https://docs.rs/strum_macros/latest/strum_macros/derive.AsRefStr.html +[IntoStaticStr]: https://docs.rs/strum_macros/latest/strum_macros/derive.IntoStaticStr.html +[EnumIter]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumIter.html +[EnumIs]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumIs.html +[EnumProperty]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumProperty.html +[EnumMessage]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumMessage.html +[EnumDiscriminants]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumDiscriminants.html +[EnumCount]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumCount.html +[FromRepr]: https://docs.rs/strum_macros/latest/strum_macros/derive.FromRepr.html +[VariantArray]: https://docs.rs/strum_macros/latest/strum_macros/derive.StaticVariantsArray.html +[VariantNames]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumVariantNames.html +[EnumTable]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumMap.html diff --git a/strum/Cargo.toml b/strum/Cargo.toml index 5713776a..7d3c961e 100644 --- a/strum/Cargo.toml +++ b/strum/Cargo.toml @@ -15,11 +15,11 @@ repository = "https://github.com/Peternator7/strum" readme = "../README.md" [dependencies] -strum_macros = { path = "../strum_macros", optional = true, version = "0.25" } +strum_macros = { path = "../strum_macros", optional = true, version = "0.26" } phf = { version = "0.10", features = ["macros"], optional = true } [dev-dependencies] -strum_macros = { path = "../strum_macros", version = "0.25" } +strum_macros = { path = "../strum_macros", version = "0.26" } [badges] travis-ci = { repository = "Peternator7/strum" } diff --git a/strum/src/lib.rs b/strum/src/lib.rs index 8038365e..7e190d9a 100644 --- a/strum/src/lib.rs +++ b/strum/src/lib.rs @@ -16,11 +16,11 @@ //! //! ```toml //! [dependencies] -//! strum = "0.25" -//! strum_macros = "0.25" +//! strum = "0.26" +//! strum_macros = "0.26" //! //! # You can also access strum_macros exports directly through strum using the "derive" feature -//! strum = { version = "0.25", features = ["derive"] } +//! strum = { version = "0.26", features = ["derive"] } //! ``` //! @@ -98,7 +98,11 @@ impl std::error::Error for ParseError { /// generic_iterator::(|color| println!("{:?}", color)); /// ``` pub trait IntoEnumIterator: Sized { - type Iterator: Iterator + Clone + DoubleEndedIterator + ExactSizeIterator + FusedIterator; + type Iterator: Iterator + + Clone + + DoubleEndedIterator + + ExactSizeIterator + + FusedIterator; fn iter() -> Self::Iterator; } @@ -219,8 +223,8 @@ pub trait VariantNames { /// enums with inner data in one or more variants. Consider using it alongside /// [`EnumDiscriminants`] if you require inner data but still want to have an /// static array of variants. -pub trait StaticVariantsArray: std::marker::Sized + 'static { - const ALL_VARIANTS: &'static [Self]; +pub trait VariantArray: std::marker::Sized + 'static { + const VARIANTS: &'static [Self]; } #[cfg(feature = "derive")] @@ -242,7 +246,6 @@ macro_rules! DocumentMacroRexports { // 2018 edition is almost 2 years old, but we'll need to give people some time to do that. DocumentMacroRexports! { AsRefStr, - AsStaticStr, Display, EnumCount, EnumDiscriminants, @@ -250,9 +253,8 @@ DocumentMacroRexports! { EnumMessage, EnumProperty, EnumString, - EnumVariantNames, + VariantNames, FromRepr, IntoStaticStr, - ToString, - StaticVariantsArray + VariantArray } diff --git a/strum_macros/Cargo.toml b/strum_macros/Cargo.toml index e91b51e4..4cdb87e9 100644 --- a/strum_macros/Cargo.toml +++ b/strum_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum_macros" -version = "0.25.3" +version = "0.26.0" edition = "2018" authors = ["Peter Glotfelty "] license = "MIT" @@ -26,4 +26,4 @@ rustversion = "1.0" syn = { version = "2.0", features = ["parsing", "extra-traits"] } [dev-dependencies] -strum = { path = "../strum" } +strum = { path = "../strum", version= "0.25" } diff --git a/strum_macros/src/helpers/mod.rs b/strum_macros/src/helpers/mod.rs index 45e77ce0..23d60b53 100644 --- a/strum_macros/src/helpers/mod.rs +++ b/strum_macros/src/helpers/mod.rs @@ -21,7 +21,7 @@ pub fn non_unit_variant_error() -> syn::Error { syn::Error::new( Span::call_site(), "This macro only supports enums of strictly unit variants. Consider \ - using it in conjunction with [`EnumDiscriminants`]" + using it in conjunction with [`EnumDiscriminants`]", ) } diff --git a/strum_macros/src/lib.rs b/strum_macros/src/lib.rs index 72eb3c0e..3a5e9854 100644 --- a/strum_macros/src/lib.rs +++ b/strum_macros/src/lib.rs @@ -170,11 +170,11 @@ pub fn as_ref_str(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// /// ``` /// // import the macros needed -/// use strum_macros::{EnumString, EnumVariantNames}; +/// use strum_macros::{EnumString}; /// // You need to import the trait, to have access to VARIANTS /// use strum::VariantNames; /// -/// #[derive(Debug, EnumString, EnumVariantNames)] +/// #[derive(Debug, EnumString, strum_macros::VariantNames)] /// #[strum(serialize_all = "kebab-case")] /// enum Color { /// Red, @@ -184,7 +184,7 @@ pub fn as_ref_str(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// } /// assert_eq!(["red", "blue", "yellow", "rebecca-purple"], Color::VARIANTS); /// ``` -#[proc_macro_derive(EnumVariantNames, attributes(strum))] +#[proc_macro_derive(VariantNames, attributes(strum))] pub fn variant_names(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast = syn::parse_macro_input!(input as DeriveInput); @@ -194,38 +194,54 @@ pub fn variant_names(input: proc_macro::TokenStream) -> proc_macro::TokenStream toks.into() } +#[doc(hidden)] +#[proc_macro_derive(EnumVariantNames, attributes(strum))] +#[deprecated( + since = "0.26.0", + note = "please use `#[derive(VariantNames)]` instead" +)] +pub fn variant_names_deprecated(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + let ast = syn::parse_macro_input!(input as DeriveInput); + + let toks = macros::enum_variant_names::enum_variant_names_inner(&ast) + .unwrap_or_else(|err| err.to_compile_error()); + debug_print_generated(&ast, &toks); + toks.into() +} + /// Adds a static array with all of the Enum's variants. -/// -/// Implements `Strum::StaticVariantsArray` which adds an associated constant `ALL_VARIANTS`. +/// +/// Implements `strum::VariantArray` which adds an associated constant `VARIANTS`. /// This constant contains an array with all the variants of the enumerator. -/// +/// /// This trait can only be autoderived if the enumerator is composed only of unit-type variants, /// meaning that the variants must not have any data. -/// +/// /// ``` -/// use strum::StaticVariantsArray; -/// -/// #[derive(StaticVariantsArray, Debug, PartialEq, Eq)] +/// use strum::VariantArray; +/// +/// #[derive(VariantArray, Debug, PartialEq, Eq)] /// enum Op { /// Add, /// Sub, /// Mul, /// Div, /// } -/// -/// assert_eq!(Op::ALL_VARIANTS, &[Op::Add, Op::Sub, Op::Mul, Op::Div]); +/// +/// assert_eq!(Op::VARIANTS, &[Op::Add, Op::Sub, Op::Mul, Op::Div]); /// ``` -#[proc_macro_derive(StaticVariantsArray, attributes(strum))] +#[proc_macro_derive(VariantArray, attributes(strum))] pub fn static_variants_array(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast = syn::parse_macro_input!(input as DeriveInput); - let toks = macros::static_variants_array::static_variants_array_inner(&ast) + let toks = macros::enum_variant_array::static_variants_array_inner(&ast) .unwrap_or_else(|err| err.to_compile_error()); debug_print_generated(&ast, &toks); toks.into() } #[proc_macro_derive(AsStaticStr, attributes(strum))] +#[doc(hidden)] #[deprecated( since = "0.22.0", note = "please use `#[derive(IntoStaticStr)]` instead" @@ -313,6 +329,7 @@ pub fn into_static_str(input: proc_macro::TokenStream) -> proc_macro::TokenStrea since = "0.22.0", note = "please use `#[derive(Display)]` instead. See issue https://github.com/Peternator7/strum/issues/132" )] +#[doc(hidden)] #[proc_macro_derive(ToString, attributes(strum))] pub fn to_string(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast = syn::parse_macro_input!(input as DeriveInput); @@ -330,9 +347,21 @@ pub fn to_string(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// choose which serialization to used based on the following criteria: /// /// 1. If there is a `to_string` property, this value will be used. There can only be one per variant. -/// 1. Of the various `serialize` properties, the value with the longest length is chosen. If that +/// 2. Of the various `serialize` properties, the value with the longest length is chosen. If that /// behavior isn't desired, you should use `to_string`. -/// 1. The name of the variant will be used if there are no `serialize` or `to_string` attributes. +/// 3. The name of the variant will be used if there are no `serialize` or `to_string` attributes. +/// 4. If the enum has a `strum(prefix = "some_value_")`, every variant will have that prefix prepended +/// to the serialization. +/// 5. Enums with named fields support named field interpolation. The value will be interpolated into the output string. +/// Note this means the variant will not "round trip" if you then deserialize the string. +/// +/// ```rust +/// #[derive(strum_macros::Display)] +/// pub enum Color { +/// #[strum(to_string = "saturation is {sat}")] +/// Red { sat: usize }, +/// } +/// ``` /// /// ``` /// // You need to bring the ToString trait into scope to use it @@ -484,10 +513,24 @@ pub fn enum_try_as(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// Creates a new type that maps all the variants of an enum to another generic value. /// -/// This macro does not support any additional data on your variants. -/// The macro creates a new type called `YourEnumTable`. -/// The table has a field of type `T` for each variant of `YourEnum`. The table automatically implements `Index` and `IndexMut`. -/// ``` +/// This macro only supports enums with unit type variants.A new type called `YourEnumTable`. Essentially, it's a wrapper +/// `[T; YourEnum::Count]` where gets/sets are infallible. Some important caveats to note: +/// +/// * The size of `YourEnumMap` increases with the number of variants, not the number of values because it's always +/// fully populated. This means it may not be a good choice for sparsely populated maps. +/// +/// * Lookups are basically constant time since it's functionally an array index. +/// +/// * Your variants cannot have associated data. You can use `EnumDiscriminants` to generate an Enum with the same +/// names to work around this. +/// +/// # Stability +/// +/// Several people expressed interest in a data structure like this and pushed the PR through to completion, but the api +/// seems incomplete, and I reserve the right to deprecate it in the future if it becomes clear the design is flawed. +/// +/// # Example +/// ```rust /// use strum_macros::EnumTable; /// /// #[derive(EnumTable)] @@ -507,9 +550,9 @@ pub fn enum_try_as(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// Color::Red => 0, /// _ => 3 /// }); +/// /// complex_map[Color::Green] = complex_map[Color::Red]; /// assert_eq!(complex_map, ColorTable::new(0, 3, 0, 3)); -/// /// ``` #[proc_macro_derive(EnumTable, attributes(strum))] pub fn enum_table(input: proc_macro::TokenStream) -> proc_macro::TokenStream { @@ -595,7 +638,6 @@ pub fn enum_table(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// assert_eq!(Some(Number::Three), number_from_repr(3)); /// assert_eq!(None, number_from_repr(4)); /// ``` - #[proc_macro_derive(FromRepr, attributes(strum))] pub fn from_repr(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast = syn::parse_macro_input!(input as DeriveInput); diff --git a/strum_macros/src/macros/static_variants_array.rs b/strum_macros/src/macros/enum_variant_array.rs similarity index 62% rename from strum_macros/src/macros/static_variants_array.rs rename to strum_macros/src/macros/enum_variant_array.rs index 2b4130cf..a6974d67 100644 --- a/strum_macros/src/macros/static_variants_array.rs +++ b/strum_macros/src/macros/enum_variant_array.rs @@ -2,7 +2,7 @@ use proc_macro2::TokenStream; use quote::quote; use syn::{Data, DeriveInput, Fields}; -use crate::helpers::{non_enum_error, HasTypeProperties, non_unit_variant_error}; +use crate::helpers::{non_enum_error, non_unit_variant_error, HasTypeProperties}; pub fn static_variants_array_inner(ast: &DeriveInput) -> syn::Result { let name = &ast.ident; @@ -20,17 +20,15 @@ pub fn static_variants_array_inner(ast: &DeriveInput) -> syn::Result Ok(v.ident), - _ => Err(non_unit_variant_error()) - } + .map(|v| match v.fields { + Fields::Unit => Ok(v.ident), + _ => Err(non_unit_variant_error()), }) .collect::>>()?; Ok(quote! { - impl #impl_generics #strum_module_path::StaticVariantsArray for #name #ty_generics #where_clause { - const ALL_VARIANTS: &'static [Self] = &[ #(#name::#idents),* ]; + impl #impl_generics #strum_module_path::VariantArray for #name #ty_generics #where_clause { + const VARIANTS: &'static [Self] = &[ #(#name::#idents),* ]; } }) } diff --git a/strum_macros/src/macros/mod.rs b/strum_macros/src/macros/mod.rs index d2d5adb1..fafc048b 100644 --- a/strum_macros/src/macros/mod.rs +++ b/strum_macros/src/macros/mod.rs @@ -2,13 +2,13 @@ pub mod enum_count; pub mod enum_discriminants; pub mod enum_is; pub mod enum_iter; -pub mod enum_table; pub mod enum_messages; pub mod enum_properties; +pub mod enum_table; pub mod enum_try_as; +pub mod enum_variant_array; pub mod enum_variant_names; pub mod from_repr; -pub mod static_variants_array; mod strings; diff --git a/strum_macros/src/macros/strings/display.rs b/strum_macros/src/macros/strings/display.rs index 34cdcddf..47432f5e 100644 --- a/strum_macros/src/macros/strings/display.rs +++ b/strum_macros/src/macros/strings/display.rs @@ -82,7 +82,7 @@ pub fn display_inner(ast: &DeriveInput) -> syn::Result { quote! { #[allow(unused_variables)] - #name::#ident #params => f.pad(&format!(#output, #args)) + #name::#ident #params => ::core::fmt::Display::fmt(&format!(#output, #args), f) } } } else { diff --git a/strum_tests/tests/enum_is.rs b/strum_tests/tests/enum_is.rs index 3226ebbc..d45ae4cb 100644 --- a/strum_tests/tests/enum_is.rs +++ b/strum_tests/tests/enum_is.rs @@ -3,9 +3,9 @@ use strum::EnumIs; mod core {} // ensure macros call `::core` #[derive(EnumIs)] -enum LifeTimeTest<'a>{ +enum LifeTimeTest<'a> { One(Cow<'a, str>), - Two(&'a str) + Two(&'a str), } #[derive(EnumIs)] enum Foo { @@ -27,7 +27,7 @@ enum Foo { Disabled, } #[test] -fn generics_test(){ +fn generics_test() { let foo = LifeTimeTest::One(Cow::Borrowed("Hello")); assert!(foo.is_one()); let foo = LifeTimeTest::Two("Hello"); diff --git a/strum_tests/tests/enum_iter.rs b/strum_tests/tests/enum_iter.rs index 8fec64bd..e670aaac 100644 --- a/strum_tests/tests/enum_iter.rs +++ b/strum_tests/tests/enum_iter.rs @@ -40,7 +40,7 @@ enum Complicated { fn complicated_test() { let results = Complicated::iter().collect::>(); let expected = vec![ - Complicated::<_,_,0>::A(0), + Complicated::<_, _, 0>::A(0), Complicated::B { v: String::new() }, Complicated::C, ]; diff --git a/strum_tests/tests/static_variants_array.rs b/strum_tests/tests/enum_variant_array.rs similarity index 69% rename from strum_tests/tests/static_variants_array.rs rename to strum_tests/tests/enum_variant_array.rs index f5f72c11..52f5e054 100644 --- a/strum_tests/tests/static_variants_array.rs +++ b/strum_tests/tests/enum_variant_array.rs @@ -1,10 +1,10 @@ -use strum::{StaticVariantsArray, EnumDiscriminants}; +use strum::{EnumDiscriminants, VariantArray}; mod core {} // ensure macros call `::core` #[test] fn simple() { - #[derive(StaticVariantsArray, PartialEq, Eq, Debug)] + #[derive(VariantArray, PartialEq, Eq, Debug)] enum Operation { Add, Sub, @@ -13,7 +13,7 @@ fn simple() { } assert_eq!( - Operation::ALL_VARIANTS, + Operation::VARIANTS, &[ Operation::Add, Operation::Sub, @@ -27,19 +27,16 @@ fn simple() { fn in_enum_discriminants() { #[allow(dead_code)] #[derive(EnumDiscriminants)] - #[strum_discriminants(derive(StaticVariantsArray))] + #[strum_discriminants(derive(VariantArray))] #[strum_discriminants(name(GeometricShapeDiscriminants))] enum GeometricShape { Point, Circle(i32), - Rectangle { - width: i32, - height: i32, - } + Rectangle { width: i32, height: i32 }, } assert_eq!( - GeometricShapeDiscriminants::ALL_VARIANTS, + GeometricShapeDiscriminants::VARIANTS, &[ GeometricShapeDiscriminants::Point, GeometricShapeDiscriminants::Circle, @@ -50,18 +47,15 @@ fn in_enum_discriminants() { #[test] fn empty_enum() { - #[derive(StaticVariantsArray, PartialEq, Eq, Debug)] + #[derive(VariantArray, PartialEq, Eq, Debug)] enum Empty {} - assert_eq!( - Empty::ALL_VARIANTS, - &[], - ); + assert_eq!(Empty::VARIANTS, &[],); } #[test] fn variants_with_values() { - #[derive(StaticVariantsArray, PartialEq, Eq, Debug)] + #[derive(VariantArray, PartialEq, Eq, Debug)] enum WeekDay { Sunday = 0, Monday = 1, @@ -73,7 +67,7 @@ fn variants_with_values() { } assert_eq!( - WeekDay::ALL_VARIANTS, + WeekDay::VARIANTS, &[ WeekDay::Sunday, WeekDay::Monday, @@ -84,4 +78,4 @@ fn variants_with_values() { WeekDay::Saturday, ], ); -} \ No newline at end of file +} diff --git a/strum_tests/tests/enum_variant_names.rs b/strum_tests/tests/enum_variant_names.rs index afd8e4dd..c6f77e6d 100644 --- a/strum_tests/tests/enum_variant_names.rs +++ b/strum_tests/tests/enum_variant_names.rs @@ -1,12 +1,12 @@ use structopt::StructOpt; -use strum::{EnumString, EnumVariantNames, VariantNames}; +use strum::{EnumString, VariantNames}; mod core {} // ensure macros call `::core` #[test] fn simple() { #[allow(dead_code)] - #[derive(EnumVariantNames)] + #[derive(VariantNames)] enum Color { Red, #[strum(serialize = "b")] @@ -21,7 +21,7 @@ fn simple() { #[test] fn variant_names_trait() { #[allow(dead_code)] - #[derive(EnumVariantNames)] + #[derive(VariantNames)] enum Color { Red, Blue, @@ -38,7 +38,7 @@ fn variant_names_trait() { #[test] fn plain_kebab() { #[allow(dead_code)] - #[derive(EnumVariantNames)] + #[derive(VariantNames)] #[strum(serialize_all = "kebab_case")] enum Color { Red, @@ -56,7 +56,7 @@ fn plain_kebab() { #[test] fn non_plain_camel() { #[allow(dead_code)] - #[derive(EnumVariantNames)] + #[derive(VariantNames)] #[strum(serialize_all = "kebab_case")] enum Color { DeepPink, @@ -85,7 +85,7 @@ fn clap_and_structopt() { color: Color, } - #[derive(Debug, EnumString, EnumVariantNames)] + #[derive(Debug, EnumString, VariantNames)] #[strum(serialize_all = "kebab_case")] enum Color { Red, @@ -116,7 +116,7 @@ fn crate_module_path_test() { } #[allow(dead_code)] - #[derive(EnumVariantNames)] + #[derive(VariantNames)] #[strum(crate = "nested::module::strum")] enum Color { Red, diff --git a/strum_tests/tests/enum_table.rs b/strum_tests/tests/enum_variant_table.rs similarity index 100% rename from strum_tests/tests/enum_table.rs rename to strum_tests/tests/enum_variant_table.rs