From 2bcf86d0ca5cb5c733031d41aacce881643433da Mon Sep 17 00:00:00 2001 From: Peter Glotfelty Date: Sat, 17 Jun 2023 17:28:04 -0700 Subject: [PATCH] Update README and CHANGELOG for new version --- .travis.yml | 2 +- CHANGELOG.md | 51 ++++++++++++++++++++++++++++++++++++ README.md | 31 +++++++++++----------- appveyor.yml | 2 +- strum/Cargo.toml | 6 ++--- strum/src/lib.rs | 19 +++++++++++--- strum_macros/Cargo.toml | 2 +- strum_nostd_tests/Cargo.toml | 2 +- strum_tests/Cargo.toml | 2 +- 9 files changed, 91 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71eafa8..eb04ad5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ rust: - stable - beta - nightly - - 1.32.0 + - 1.56.1 matrix: allow_failures: - rust: nightly diff --git a/CHANGELOG.md b/CHANGELOG.md index c8ce511..d0920f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,56 @@ # Changelog +## 0.25.0 + +### Breaking Changes + +* [#261](https://github.com/Peternator7/strum/pull/261) Upgrade syn dependency to version 2. This bumps the msrv to + 1.56. It's impractical to maintain a package where a core dependency of the ecosystem has a different msrv than this one. + +* [270](https://github.com/Peternator7/strum/pull/270) Change the `to_string` behavior when using `default`. Now, when + using `default`, the `display` method will return the display version of the value contained in the enum rather than + the name of the variant. + + ```rust + #[derive(strum::Display)] + enum Color { + Red, + Blue, + Green, + #[strum(default)] + Other(String) + } + + fn main() { + // This used to print "Other", now it prints "Purple" + assert_eq!(Color::Other("Purple".to_string()).to_string(), "Purple"); + } + ``` + + If you want the old behavior, you can use the `to_string` attribute to override this behavior. See the PR for an example. + +* [268](https://github.com/Peternator7/strum/pull/268) Update the behavior of `EnumCount` to exclude variants that are + `disabled`. This is a breaking change, but the behavior makes it more consistent with other methods. + +### New Features + +* [#257](https://github.com/Peternator7/strum/pull/257) This PR adds the `EnumIs` macro that automatically implements + `is_{variant_name}` methods for each variant. + + ```rust + #[derive(EnumIs)] + enum Color { + Red, + Blue, + Green, + } + + #[test] + fn simple_test() { + assert!(Color::Red.is_red()); + } + ``` + ## 0.24.3 (strum_macros) * [#231](https://github.com/Peternator7/strum/pull/231) Add ignore lints for EnumIter not implementing Copy or Debug diff --git a/README.md b/README.md index 484630c..491c24f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Strum is a set of macros and traits for working with enums and strings easier in # Compatibility -Strum is currently compatible with versions of rustc >= 1.32.0. Pull Requests that improve compatibility with older +Strum is currently compatible with versions of rustc >= 1.56.1. Pull Requests that improve compatibility with older versions are welcome. The project goal is to support a rust version for at least 2 years after release and even longer is preferred since this project changes slowly. @@ -22,11 +22,11 @@ Cargo.toml. Strum_macros contains the macros needed to derive all the traits in ```toml [dependencies] -strum = "0.24" -strum_macros = "0.24" +strum = "0.25" +strum_macros = "0.25" # You can also use the "derive" feature, and import the macros directly from "strum" -# strum = { version = "0.24", features = ["derive"] } +# strum = { version = "0.25", features = ["derive"] } ``` # Strum Macros @@ -68,14 +68,15 @@ information through strings. Strumming is also a very whimsical motion, much like writing Rust code. [Macro-Renames]: https://github.com/Peternator7/strum/wiki/Macro-Renames -[EnumString]: https://docs.rs/strum_macros/0.24/strum_macros/derive.EnumString.html -[Display]: https://docs.rs/strum_macros/0.24/strum_macros/derive.Display.html -[AsRefStr]: https://docs.rs/strum_macros/0.24/strum_macros/derive.AsRefStr.html -[IntoStaticStr]: https://docs.rs/strum_macros/0.24/strum_macros/derive.IntoStaticStr.html -[EnumVariantNames]: https://docs.rs/strum_macros/0.24/strum_macros/derive.EnumVariantNames.html -[EnumIter]: https://docs.rs/strum_macros/0.24/strum_macros/derive.EnumIter.html -[EnumProperty]: https://docs.rs/strum_macros/0.24/strum_macros/derive.EnumProperty.html -[EnumMessage]: https://docs.rs/strum_macros/0.24/strum_macros/derive.EnumMessage.html -[EnumDiscriminants]: https://docs.rs/strum_macros/0.24/strum_macros/derive.EnumDiscriminants.html -[EnumCount]: https://docs.rs/strum_macros/0.24/strum_macros/derive.EnumCount.html -[FromRepr]: https://docs.rs/strum_macros/0.24/strum_macros/derive.FromRepr.html +[EnumString]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumString.html +[Display]: https://docs.rs/strum_macros/0.25/strum_macros/derive.Display.html +[AsRefStr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.AsRefStr.html +[IntoStaticStr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.IntoStaticStr.html +[EnumVariantNames]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumVariantNames.html +[EnumIter]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumIter.html +[EnumIs]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumIs.html +[EnumProperty]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumProperty.html +[EnumMessage]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumMessage.html +[EnumDiscriminants]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumDiscriminants.html +[EnumCount]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumCount.html +[FromRepr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.FromRepr.html diff --git a/appveyor.yml b/appveyor.yml index 9bf3377..04e3dc8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -135,7 +135,7 @@ test_script: for: - matrix: only: - - channel: 1.32.0 + - channel: 1.56.1 test_script: - cargo test --verbose %cargoflags% \ No newline at end of file diff --git a/strum/Cargo.toml b/strum/Cargo.toml index 4472ca8..5713776 100644 --- a/strum/Cargo.toml +++ b/strum/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum" -version = "0.24.1" +version = "0.25.0" edition = "2018" authors = ["Peter Glotfelty "] license = "MIT" @@ -15,11 +15,11 @@ repository = "https://github.com/Peternator7/strum" readme = "../README.md" [dependencies] -strum_macros = { path = "../strum_macros", optional = true, version = "0.24" } +strum_macros = { path = "../strum_macros", optional = true, version = "0.25" } phf = { version = "0.10", features = ["macros"], optional = true } [dev-dependencies] -strum_macros = { path = "../strum_macros", version = "0.24" } +strum_macros = { path = "../strum_macros", version = "0.25" } [badges] travis-ci = { repository = "Peternator7/strum" } diff --git a/strum/src/lib.rs b/strum/src/lib.rs index a9e8444..7fbe5e2 100644 --- a/strum/src/lib.rs +++ b/strum/src/lib.rs @@ -16,11 +16,11 @@ //! //! ```toml //! [dependencies] -//! strum = "0.24" -//! strum_macros = "0.24" +//! strum = "0.25" +//! strum_macros = "0.25" //! //! # You can also access strum_macros exports directly through strum using the "derive" feature -//! strum = { version = "0.24", features = ["derive"] } +//! strum = { version = "0.25", features = ["derive"] } //! ``` //! @@ -101,6 +101,19 @@ pub trait IntoEnumIterator: Sized { fn iter() -> Self::Iterator; } +pub trait VariantIterator: Sized { + type Iterator: Iterator; + + fn iter() -> Self::Iterator; +} + +pub trait VariantMetadata { + const VARIANT_COUNT: usize; + const VARIANT_NAMES: &'static [&'static str]; + + fn variant_name(&self) -> &'static str; +} + /// Associates additional pieces of information with an Enum. This can be /// autoimplemented by deriving `EnumMessage` and annotating your variants with /// `#[strum(message="...")]`. diff --git a/strum_macros/Cargo.toml b/strum_macros/Cargo.toml index 60e5b57..2b43569 100644 --- a/strum_macros/Cargo.toml +++ b/strum_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum_macros" -version = "0.24.3" +version = "0.25.0" edition = "2018" authors = ["Peter Glotfelty "] license = "MIT" diff --git a/strum_nostd_tests/Cargo.toml b/strum_nostd_tests/Cargo.toml index 1c0ee47..6403638 100644 --- a/strum_nostd_tests/Cargo.toml +++ b/strum_nostd_tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum_nostd_tests" -version = "0.24.0" +version = "0.25.0" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/strum_tests/Cargo.toml b/strum_tests/Cargo.toml index 6a179ea..3f28b1c 100644 --- a/strum_tests/Cargo.toml +++ b/strum_tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum_tests" -version = "0.24.0" +version = "0.25.0" edition = "2018" authors = ["Peter Glotfelty "]