* 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
* Add get_documentation() to EnumMessage.
* Address 1st review comments.
* Remove usage of strip_prefix to support older Rust versions.
Co-authored-by: Peter Glotfelty <glotfelty.2@osu.edu>
* add clippy.toml with an msrv
* fix clippy lints
* replace inefficient algorithm
* replace ::std with ::core in more places and comments
* fix some test warnings
* fix clippy lints in tests
* Add EnumConstIndex
* Get working with discriminants
* Remove unused/(unneeded?) features
* Rename to EnumIndex and index(..). Make const_index conditional
* Get repr(..) working
* Fix issue to support rust 1.32
* Switch from VARIANT# to {ENUM}_{VARIANT} for variant constant names
* Expose constants as part of implementation
* Add discriminant error messages. Cargo fmt my code
* Add rustversion to make compilation conditional on 1.46
* Handle expr discriminants
* Fix generics handling
* Make constants always available. No need to only expose them when const_index is defined
* Change to FromDiscriminant. Only output a single function
* Don't make constants accessible
* Make rustversion a dev dependency in strum-tests due to upstream change
* Cleanup doc tests for const
* Rename to FromRepr/from_repr
The implementation simply delegates to `std::str::FromStr`.
To maintain compatibility with Rust 1.32, a new dependency
is introduced which allows us to emit the `TryFrom<&str>`
implementation only for Rust 1.34 and above when
`std::convert::TryFrom` was stabilized.
* Adding vis to EnumDiscriminants (#137)
* Improved doctest example names (#137)
* Fixing incorrect occurrence_error attr string
* Using r#pub on doctest
* Adding tests for discriminant visibility, and rustc-cfg for bare "pub"
* Doing local import with "self::"
* Back to having tests pass on latest stable
* Moved sample doctest with vis example to separate nocompile block
* Remove unused method NestedMetaHelpers::expect_lit
* Use references match instead of ref patterns
* Use custom meta types instead of syn::Meta
This should improve both readability of the code and the quality of
error messages.
* Replace TryFrom<&str> with FromStr
* Restore Rust 1.31.1 compatibility
* Re-run `cargo fmt`
* Implemented DoubleEndedIterator for EnumIter.
* Fixed overlapping behaviour of next and next_back.
* Changed names of tests I accidentally swapped.
* Fixed size_hint() for EnumIter.
* Implemented more efficient version of nth() for EnumIter.
* Added another test of `next` and `next_back`, where the last call is to `next`.
* Add VariantNames trait with the variants() function which the EnumVariantNames macro implements
* Consider generics in the impl block + use absolute path for the trait
* Add `EnumVariantNames`
This derive adds a static `variants()` methods yielding the names of
the enum variants. This happens to be exactly what clap [wants][1], and
is the last puzzle piece to use strum with clap/structopt.
[1]: https://docs.rs/clap/2.33.0/clap/macro.arg_enum.html
* Expand readme section for `EnumVariantNames`
* Return slice instead of array
This reduces the risk of breaking the public API by accident when adding
a new variant.
* Fix typo in Readme
* Add generic doc comment to `variants()` method
* Add test case using `variants` in clap/structopt
* Updating the README
* Did lots of updates for the documentation
* Improving formatting in a few places
* Consolidated docs to make it easier to keep up to date
* Updating workspace
* Revved version in docs