1
0
mirror of https://github.com/danog/strum.git synced 2024-12-02 09:27:57 +01:00
Commit Graph

73 Commits

Author SHA1 Message Date
bouzuya
fcb9841a74
Add test and comment if camel_case is specified (#250)
Co-authored-by: Peter Glotfelty <glotfelty.2@osu.edu>
2023-07-29 15:00:13 -07:00
kraktus
fd519ec47f
Fix EnumIter macro code generation (#287)
* 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>
2023-07-29 14:58:18 -07:00
Samuel Moelius
93ea44dd12
Handle rustoc comments in #[derive(FromRepr)] (#276) 2023-07-03 13:45:32 -07:00
Peter Glotfelty
2bcf86d0ca Update README and CHANGELOG for new version 2023-06-17 17:28:04 -07:00
Mendy Berger
85e2c1692b
Added enum_is (#257)
* Added enum_is

* feat(is): Use a simple match and cover all cases

* Removed dependency convert_case

* Added disabled support for enum_is
2023-06-17 17:58:53 -07:00
Josh McKinney
e6a9bf08c4
fix!: use the tuple value for to_string on default (#270)
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)
```
2023-06-17 17:58:12 -07:00
Matt Schulte
67f0d1947d
Fix EnumCount with disabled variants (#268)
Do not include disabled variants in the count with EnumCount. Fixes #267
2023-06-17 17:50:15 -07:00
Peter Glotfelty
b5ba7cc12c
Revert "Add TryFrom to FromRepr (#217)" (#228)
This reverts commit ac757fa970.
2022-06-24 17:47:32 -07:00
Peter Glotfelty
b1befeb594 See if this gets the build fixed 2022-04-30 15:26:54 -07:00
Ten0
832dd862c7
Add support for PHF in EnumString (#220)
* 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
2022-04-30 15:23:28 -07:00
ac757fa970
Add TryFrom to FromRepr (#217)
* Add TryFrom to FromRepr

* Fix building on rust < 1.34
2022-04-30 11:24:17 -07:00
Peter Glotfelty
96228c76cb Add updates for 0.24 2022-02-21 14:07:48 -08:00
Oren Ben-Kiki
e558e913f4
Add get_documentation() to EnumMessage. (#206)
* 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>
2022-02-21 13:37:25 -08:00
Marcel Hellwig
672ac26005
Clippy lints and some minor nitpicks (#212)
* 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
2022-02-18 16:04:31 -08:00
Peter Glotfelty
837c785a88
Pin clap version (#205)
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2022-01-09 09:37:17 -08:00
Peter Glotfelty
0c80602333
Add tests for nostd environment (#196)
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2021-11-20 11:30:11 -08:00
Peter Glotfelty
c8cd49f4e3 Use rustversion instead of version_check in strum_tests 2021-11-16 21:56:51 -08:00
Andrew Burkett
aeaa19ad86
EnumIndex implementation (#185)
* 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
2021-11-06 09:30:09 -07:00
Dominik Spicher
7b68e4dc44
Add TryFrom<&str> to EnumString (#186)
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.
2021-10-26 12:16:57 -07:00
Peter Glotfelty
08583fcb11
Make changes necessary for version 0.22 (#181)
* Make changes necessary for version 0.22

* Update changelog

Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2021-10-10 20:47:24 -07:00
Peter Glotfelty
75519edcff pin bitflags version in tests project to fix builds 2021-10-02 08:30:03 -07:00
Billy Chan
e9d3b59a80
Re-export macros (#170)
* Re-exportable macros

* Rename derive attribute to `Crate`

* Add unit tests

* Test nested module

* Rename derive attribute to `crate`

* cargo fmt
2021-07-16 20:40:19 -07:00
Peter Glotfelty
c5a4b5e932
Update docs for 0.21 (#163)
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2021-06-01 18:32:56 -07:00
Peter Glotfelty
f71830c5fe
Pin exact version of enum_variant_type (#162) 2021-05-15 00:28:52 -07:00
Chayim Refael Friedman
ca60910df0
Support case-insensitive EnumString (#157)
Fixes #154
2021-05-02 20:59:48 -07:00
Vlad Frolov
089aec8303
Added a pass-through attribute support to EnumDiscriminants (#153)
* Added a pass-through attribute support to EnumDiscriminants

* added a test per review comment
2021-03-19 10:45:55 -07:00
Peter Glotfelty 🚀
96ee0a9a30 Updated changelog for strum 0.20 2020-11-21 20:13:44 +00:00
Mark LeMoine
ddb9c2682e
Adding visibility option vis(...) to #[strum_discriminants] (#137) (#138)
* 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
2020-11-15 20:13:50 -08:00
Jonas Platte
25eaa5a12c
More attribute refactoring (#134)
* 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`
2020-10-15 09:27:38 -07:00
Peter Glotfelty 🚀
441316121b Updated changelog and readme with new version as well as tweaked docs slightly. 2020-10-07 05:52:12 +00:00
Peter Glotfelty
1d2778842b
Re-Enable Travis via travis.com (#112)
* Enable travis

* add build.r to re-enable try_from
2020-09-17 11:21:41 -07:00
Jonas Platte
b517f232aa
Update strum to Rust edition 2018 (#110)
* Set all crates to edition 2018

* Remove redundant imports

* Remove extern crate declarations for cargo dependencies
2020-09-17 11:21:21 -07:00
Peter Glotfelty 🚀
38fdea4ad8 Fix issues that were preventing the code from compiling on 1.31.1 2020-09-17 05:01:05 +00:00
Peter Glotfelty 🚀
06bbb62624 ran cargo fmt over the whole tree 2020-08-06 00:09:12 +00:00
Peter Glotfelty 🚀
9508a31f4b Didn't actually change enum variant names in the 0.19 like I meant to. 2020-08-02 00:07:38 +00:00
Peter Glotfelty
7e5b5e43e8
Peternator7/0.19 (#101)
* Changelog for 0.19

* Updated version in Cargo.toml
2020-08-01 16:54:43 -07:00
Peter Glotfelty
c5fc096ece
Pulled some of the core logic out of plugins (#100)
* Major refactor of code.

* More minor refactorings

* renamed variables

* add repository link
2020-07-29 09:36:48 -07:00
Peter Glotfelty 🚀
ec3297242c Replaced const fn count with associated constant. 2020-07-26 04:41:15 +00:00
Peter Glotfelty
95645cac52
Fix Display macro to handle fill/align (#95) 2020-06-12 13:54:51 -07:00
root
da37cc3141 Made a fix for #80 2020-03-01 23:55:53 +00:00
t-mw
043b60f6d8
Apply serialize_all casing to get_serializations (#84)
* Apply serialize_all casing to get_serializations

* Update changelog

* Fix grammar
2020-02-10 15:55:18 -08:00
Azriel Hoh
2b83eceba6
Bugfix/73/whitelist variant attributes to copy (#82)
* Whitelist attributes to copy to `EnumDiscriminants`' variants.

* Updated `CHANGELOG.md`.
2020-02-08 10:54:44 -08:00
Nevsor
8db6a31332 Implemented DoubleEndedIterator for EnumIter. (#60)
* 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`.
2019-12-19 14:44:30 -08:00
Waffle Lapkin
eea32dbf7f Const enum variants names (#75)
* Add implementing const `VARIANTS` by `EnumVariantsNames`, deprecate old `::variants`

* Move `const VARIANTS` to `VariantNames` trait

* Remove `VariantNames::variants` function
2019-12-12 13:39:10 -08:00
Spanfile
bc8fa93ee8 Move EnumVariantsNames into a trait which the macro implements (#74)
* Add VariantNames trait with the variants() function which the EnumVariantNames macro implements

* Consider generics in the impl block + use absolute path for the trait
2019-11-23 20:58:10 -08:00
Herman Venter
e981f240d6 Add checks to guard against overflow in iterator methods. (#76) 2019-11-16 17:33:14 -08:00
uHOOCCOOHu
00397fe0a3 Add feature derive for re-exporting proc macros. 2019-08-16 11:52:58 -07:00
Evgeniy Dushistov
640c0bb713 Implement serialize_all=UPPERCASE (#48)
* Implement serialize_all=UPPERCASE

* applying rustfmt 1.2.2-stable

* handling of all options listed in serde docs for compatibility

See https://serde.rs/container-attrs.html#container-attributes
2019-07-29 08:26:29 -07:00
Pascal Hertleif
96daaf4021 Add EnumVariantNames (#56)
* 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
2019-07-15 10:06:33 -07:00
Peter Glotfelty
970b5cec40
Macro renames (#46)
* 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
2019-03-26 20:44:39 -07:00