The concrete Iterator type for all implementations of
IntoEnumIterator is guaranteed to implement these traits, because
the only implementor is the `#[derive(EnumIter)]` macro, which
emits an impl for each for the generated {EnumType}Iter struct.
However, when using IntoEnumIterator as a generic constraint, the
concrete type is not known, so the impl of these traits cannot be
inferred by the type checker with out additional help.
Here are some examples, using Itertools::cartesian_product() as
the motivator, because it requires `Iterator + Clone`:
// We know this function will work, but it fails to type check
// without these additional trait bounds on IntoEnumIterator.
pub fn example_broken<T: Clone + IntoEnumIterator, U: Clone + IntoEnumIterator>(
) -> impl Iterator<Item = (T, U)> + Clone {
T::iter().cartesian_product(U::iter())
}
// It's possible to add where constraints at the use point to
// workaround the issue, without this change.
// This version will typecheck.
pub fn example_workaround<T: Clone + IntoEnumIterator, U: Clone + IntoEnumIterator>(
) -> impl Iterator<Item = (T, U)>
where
<T as IntoEnumIterator>::Iterator: Clone,
<U as IntoEnumIterator>::Iterator: Clone,
{
T::iter().cartesian_product(U::iter())
}
* moved repr extraction to helpers
* repr pass-through added
* add discriminant pass through
* remove dev artifact
---------
Co-authored-by: Jason Scatena <jscatena@amazon.com>
* Add test to ensure macro call `::core`-related functions
Avoiding local core modules to break the macro-generated code.
Currently failing due to issue with `EnumIter` macros.
* Fix macro of `EnumIter`
close https://github.com/Peternator7/strum/issues/284
---------
Co-authored-by: kraktus <kraktus@users.noreply.github.com>
The default attribute on a tuple like variant now causes the to_string
and display format to use the value of the tuple rather than the name
of the variant.
E.g. Color::Green("lime").to_string() will equal "lime" not "Green"
Fixes: how to round trip Display and EnumString with default="true" #86
BREAKING CHANGE
This changes how Display and ToString cause the following to renders:
```rust
#[strum(default)]
Green(String)
```
To maintain the previous behavior (use the variant name):
```rust
#[strum(default, to_string("Green"))]
Green(String)
```
* Support phf crate for faster match on large enums
* comment
* add changelog entry
* add tests, embed phf, and improve lowercase support
* fix doc change
* Refactor & support case insensitive with case sensitive phf match
* more tests, some fixes of new implementation and prep for feature
* Modify the initial implementation.
Co-authored-by: Thomas BESSOU <thomas.bessou@hotmail.fr>
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
* Support phf crate for faster match on large enums
* comment
* add changelog entry
* add tests, embed phf, and improve lowercase support
* fix doc change
* Refactor & support case insensitive with case sensitive phf match
* more tests, some fixes of new implementation and prep for feature