1
0
mirror of https://github.com/danog/strum.git synced 2024-11-30 04:28:59 +01:00
Commit Graph

203 Commits

Author SHA1 Message Date
3d02957330 Merge remote-tracking branch 'o/master' 2023-12-11 21:24:28 +01:00
Josh Channings
ffe8873ae7
Add Iterator trait bounds to IntoEnumIterator (#314)
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())
}
2023-12-02 16:28:57 -08:00
Peter Glotfelty
62c1150844 Merge branch 'jwodder-iter-traits' 2023-10-29 12:30:34 -07:00
Peter Glotfelty
84cf8d2a32 Support FusedIteratorOnly 2023-10-29 12:29:44 -07:00
Peter Glotfelty
9660ec4096 Merge branch 'iter-traits' of https://github.com/jwodder/strum into jwodder-iter-traits 2023-10-29 12:24:49 -07:00
Jason Scatena
e8b2ff1b48
EnumDiscriminant inherits the repr and discriminant values (#288)
* moved repr extraction to helpers

* repr pass-through added

* add discriminant pass through

* remove dev artifact

---------

Co-authored-by: Jason Scatena <jscatena@amazon.com>
2023-10-28 18:57:36 -07:00
Peter Glotfelty
d32af44f2e
Fix "Display" for non string Defaults (#308)
* Fix "Display" for non string Defaults

* This version actually works :)

---------

Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2023-10-28 18:55:52 -07:00
John T. Wodder II
7831f6f1f7 Impl Copy, Eq, and FusedIterator for EnumIter iterators 2023-10-28 18:35:32 -04:00
Peter Glotfelty
597f8e941f publish 0.25.3 2023-10-14 12:21:13 -07:00
horacimacias
42c16664a8
Fix EnumIter for enums named Option (#300)
Co-authored-by: Horaci Macias <hmacias@avaya.com>
2023-10-15 15:08:35 -07:00
Wyatt Herkamp
0199235bb0
Fix Generics Issue with enum_is (#305) 2023-10-15 15:07:46 -07:00
Michael Schubart
3664c5e8ca
Remove unused vectors (#304) 2023-10-15 15:06:49 -07:00
Wyatt Herkamp
af9b15b617
Add doc comment to EnumIs result (#301) 2023-10-15 15:05:55 -07:00
Peter Glotfelty
db553e3dcf
Merge pull request #285 from MendyBerger:try-as
Added EnumTryAs
2023-08-26 14:49:58 -07:00
Peter Glotfelty
3341c2f394 updated changelog to 0.25.2 2023-08-06 16:55:18 -07:00
hasezoey
2782412396
Enable doc-test for "strum_discriminants(vis(pub))" (#289) 2023-08-06 16:48:02 -07:00
Mendy Berger
4014b3e2d1 Requested changes in review 2023-07-31 16:44:38 -04:00
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
MendyBerger
e0f81e9caa Added EnumTryAs 2023-07-16 22:59:38 -04:00
Peter Glotfelty
96c63e9f5c Fix a typo in Changelog wrt new version 2023-07-03 14:42:27 -07:00
Peter Glotfelty
69e3449c0e Publish new version with fix #276 2023-07-03 13:49:32 -07:00
Samuel Moelius
93ea44dd12
Handle rustoc comments in #[derive(FromRepr)] (#276) 2023-07-03 13:45:32 -07:00
Peter Glotfelty
0a0def76bd
update ci version (#280)
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2023-07-01 13:17:30 -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
CosmicHorror
2b71e10120
Update syn to v2 (#261) 2023-06-17 17:57:26 -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
Jan Philipp Bittner
025b1b5687
add missing word (#263) 2023-05-06 15:24:04 -07:00
Rory Snively
30c5c16515
fix deprecation warning in additional_attributes example (#264) 2023-05-06 14:55:43 -07:00
Martin Kauppinen
635ab9511b
Add Train-Case case style (#256) 2023-03-12 14:48:07 -07:00
Kesavan Yogeswaran
405832679f
Fix doc comment for strum::EnumIter macro (#253)
The `EnumIter` macro's doc comment has a typo around the implemented
trait. The implemented trait is `strum::IntoEnumIterator`.
2023-02-26 11:08:58 -08:00
Alex
7efb86efbe
Change kebab_case to kebab-case in example (#248) 2023-01-02 16:00:42 -08:00
Peter Glotfelty
e772e203da
implement Debug for EnumIter (#240)
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2022-10-15 12:00:20 -07:00
Mike Leany
dd0c2fa785
Fix doc comment for EnumIter (#242)
Comment now says that it iterates over variants of the enum rather than
variants of `Self`, which would be the iterator.
2022-10-15 11:59:55 -07:00
Alissa Tung
93d0886377
chore: fix typo (#239)
* chore: fix typo

* chore: fix typo
2022-09-25 12:10:49 -07:00
Tim Siegel
54771c0870
strum_macros::FromRepr: fix typo in documentation (#236) 2022-09-19 10:31:34 -07:00
Peter Glotfelty
7e8a9304bf Update changelog 2022-08-07 16:35:38 -07:00
Peter Glotfelty
d8278db866
add allows to prevent lint errors (#231)
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2022-08-07 16:32:28 -07:00
Peter Glotfelty
0ba53fff6c Publishing a new version without #217 to enable phf 2022-06-24 17:53:45 -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
5685f9b96d updated CHANGELOG with yanked package 2022-06-16 07:44:41 -07:00
Peter Glotfelty
b25ea1b9a0 Get ready to publish 0.24.1 2022-06-12 13:33:21 -07:00
Peter Glotfelty
a952fc0028
Peternator7/update phf logic (#224)
* 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>
2022-05-16 21:33:33 -07:00
Peter Glotfelty
c560f3e4c0
Disable the test_phf feature on 1.32 (#222)
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
2022-05-01 08:54:09 -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
cf34a64ee9
Fix building on rust < 1.34 2022-04-19 21:06:39 +02:00