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
* 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
The addition of TryFrom<&str> for EnumString breaks for enums that have
a variant called "Error". Rewrite as <Self as Trait> where associated
types are used as the return type for trait functions.
Example:
```rust
pub enum Test {
Error,
}
```
error: ambiguous associated item
--> src/lib.rs:3:10
|
3 | #[derive(EnumString)]
| ^^^^^^^^^^
|
= note: `#[deny(ambiguous_associated_items)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
* 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.