Skip to content

Commit

Permalink
Update Changelog etc in prep for release (#324)
Browse files Browse the repository at this point in the history
* Get files ready for release

* More documentation.

---------

Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
  • Loading branch information
Peternator7 and Peter Glotfelty committed Jan 28, 2024
1 parent 33b93b4 commit 22606ef
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 96 deletions.
76 changes: 76 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,81 @@
# Changelog

## 0.26.0

### Breaking Changes

* The `EnumVariantNames` macro has been renamed `VariantNames`. The deprecation warning should steer you in
the right direction for fixing the warning.
* The Iterator struct generated by EnumIter now has new bounds on it. This shouldn't break code unless you manually
added the implementation in your code.
* `Display` now supports format strings using named fields in the enum variant. This should be a no-op for most code.
However, if you were outputting a string like `"Hello {field}"`, this will now be interpretted as a format string.


### New features

* The `VariantArray` macro has been added. This macro adds an associated constant `VARIANTS` to your enum. The constant
is a `&'static [Self]` slice so that you can access all the variants of your enum. This only works on enums that only
have unit variants.

```rust
use strum::VariantArray;

#[derive(Debug, VariantArray)]
enum Color {
Red,
Blue,
Green,
}

fn main() {
println!("{:?}", Color::VARIANTS); // prints: ["Red", "Blue", "Green"]
}
```

* The `EnumMap` macro has been *experimentally* added. This macro adds a new type that stores an item for each variant
of the enum. This is useful for storing a value for each variant of an enum. This is an experimental feature because
I'm not convinced the current api surface area is correct.

```rust
use strum::EnumMap;

#[derive(Copy, Clone, Debug, EnumMap)]
enum Color {
Red,
Blue,
Green,
}

fn main() {
let mut counts = ColorTable::filled(0);
for color in &[Color::Red, Color::Red, Color::Green]] {
counts[color] += 1;
}

assert_eq!(counts[Color::Red], 2);
assert_eq!(counts[Color::Blue], 0);
assert_eq!(counts[Color::Green], 1);
}
```

* `Display` has 2 new features:
* the `strum(prefix = "some_value")` attribute on an enum now allows you to prepend a string onto every
variant when you serialize it.

* Custom `to_string` and `serialize` attributes now support string interopolation on serialization.

### PR's Merged

* [#322](https://github.com/Peternator7/strum/pull/322): avoid collisions on `std::fmt::Debug`
* [#321](https://github.com/Peternator7/strum/pull/321): avoid conflicts with consecutive underscores.
* [#314](https://github.com/Peternator7/strum/pull/314): add additional bounds to EnumIterator
* [#311](https://github.com/Peternator7/strum/pull/311): add FusedIterator bounds to EnumIterator
* [#297](https://github.com/Peternator7/strum/pull/297): New macro, add `VariantArray`
* [#296](https://github.com/Peternator7/strum/pull/296): adds prefix attribute to To/From String macros.
* [#294](https://github.com/Peternator7/strum/pull/294): use named enum fields in to_string macro.


## 0.25.3 (strum_macros)

Received a number of bug fix PR's.
Expand Down
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Cargo.toml. Strum_macros contains the macros needed to derive all the traits in

```toml
[dependencies]
strum = "0.25"
strum_macros = "0.25"
strum = "0.26"
strum_macros = "0.26"

# You can also use the "derive" feature, and import the macros directly from "strum"
# strum = { version = "0.25", features = ["derive"] }
# strum = { version = "0.26", features = ["derive"] }
```

# Strum Macros
Expand All @@ -40,18 +40,21 @@ Strum has implemented the following macros:
| [FromRepr] | Convert from an integer to an enum. |
| [AsRefStr] | Implement `AsRef<str>` for `MyEnum` |
| [IntoStaticStr] | Implements `From<MyEnum> for &'static str` on an enum |
| [EnumVariantNames] | Adds an associated `VARIANTS` constant which is an array of discriminant names |
| [EnumIter] | Creates a new type that iterates of the variants of an enum. |
| [EnumMap] | Creates a new type that stores an item of a specified type for each variant of the enum. |
| [EnumProperty] | Add custom properties to enum variants. |
| [EnumMessage] | Add a verbose message to an enum variant. |
| [EnumDiscriminants] | Generate a new type with only the discriminant names. |
| [EnumCount] | Add a constant `usize` equal to the number of variants. |
| [StaticVariantsArray] | Adds an associated `ALL_VARIANTS` constant which is an array of all enum discriminants |
| [VariantArray] | Adds an associated `VARIANTS` constant which is an array of all enum discriminants |
| [VariantNames] | Adds an associated `VARIANTS` constant which is an array of discriminant names |
| [EnumTable] | *Experimental*, creates a new type that stores an item of a specified type for each variant of the enum. |

# Contributing

Thanks for your interest in contributing. The project is divided into 3 parts, the traits are in the
Thanks for your interest in contributing. Bug fixes are always welcome. If you are interested in implementing or
adding a macro, please open an issue first to discuss the feature. I have limited bandwidth to review new features.

The project is divided into 3 parts, the traits are in the
`/strum` folder. The procedural macros are in the `/strum_macros` folder, and the integration tests are
in `/strum_tests`. If you are adding additional features to `strum` or `strum_macros`, you should make sure
to run the tests and add new integration tests to make sure the features work as expected.
Expand All @@ -69,17 +72,17 @@ 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.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
[StaticVariantsArray]: https://docs.rs/strum_macros/0.25/strum_macros/derive.StaticVariantsArray.html
[Display]: https://docs.rs/strum_macros/latest/strum_macros/derive.Display.html
[AsRefStr]: https://docs.rs/strum_macros/latest/strum_macros/derive.AsRefStr.html
[IntoStaticStr]: https://docs.rs/strum_macros/latest/strum_macros/derive.IntoStaticStr.html
[EnumIter]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumIter.html
[EnumIs]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumIs.html
[EnumProperty]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumProperty.html
[EnumMessage]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumMessage.html
[EnumDiscriminants]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumDiscriminants.html
[EnumCount]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumCount.html
[FromRepr]: https://docs.rs/strum_macros/latest/strum_macros/derive.FromRepr.html
[VariantArray]: https://docs.rs/strum_macros/latest/strum_macros/derive.StaticVariantsArray.html
[VariantNames]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumVariantNames.html
[EnumTable]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumMap.html
4 changes: 2 additions & 2 deletions strum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ repository = "https://github.com/Peternator7/strum"
readme = "../README.md"

[dependencies]
strum_macros = { path = "../strum_macros", optional = true, version = "0.25" }
strum_macros = { path = "../strum_macros", optional = true, version = "0.26" }
phf = { version = "0.10", features = ["macros"], optional = true }

[dev-dependencies]
strum_macros = { path = "../strum_macros", version = "0.25" }
strum_macros = { path = "../strum_macros", version = "0.26" }

[badges]
travis-ci = { repository = "Peternator7/strum" }
Expand Down
22 changes: 12 additions & 10 deletions strum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
//!
//! ```toml
//! [dependencies]
//! strum = "0.25"
//! strum_macros = "0.25"
//! strum = "0.26"
//! strum_macros = "0.26"
//!
//! # You can also access strum_macros exports directly through strum using the "derive" feature
//! strum = { version = "0.25", features = ["derive"] }
//! strum = { version = "0.26", features = ["derive"] }
//! ```
//!

Expand Down Expand Up @@ -98,7 +98,11 @@ impl std::error::Error for ParseError {
/// generic_iterator::<Color, _>(|color| println!("{:?}", color));
/// ```
pub trait IntoEnumIterator: Sized {
type Iterator: Iterator<Item = Self> + Clone + DoubleEndedIterator + ExactSizeIterator + FusedIterator;
type Iterator: Iterator<Item = Self>
+ Clone
+ DoubleEndedIterator
+ ExactSizeIterator
+ FusedIterator;

fn iter() -> Self::Iterator;
}
Expand Down Expand Up @@ -219,8 +223,8 @@ pub trait VariantNames {
/// enums with inner data in one or more variants. Consider using it alongside
/// [`EnumDiscriminants`] if you require inner data but still want to have an
/// static array of variants.
pub trait StaticVariantsArray: std::marker::Sized + 'static {
const ALL_VARIANTS: &'static [Self];
pub trait VariantArray: std::marker::Sized + 'static {
const VARIANTS: &'static [Self];
}

#[cfg(feature = "derive")]
Expand All @@ -242,17 +246,15 @@ macro_rules! DocumentMacroRexports {
// 2018 edition is almost 2 years old, but we'll need to give people some time to do that.
DocumentMacroRexports! {
AsRefStr,
AsStaticStr,
Display,
EnumCount,
EnumDiscriminants,
EnumIter,
EnumMessage,
EnumProperty,
EnumString,
EnumVariantNames,
VariantNames,
FromRepr,
IntoStaticStr,
ToString,
StaticVariantsArray
VariantArray
}
4 changes: 2 additions & 2 deletions strum_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "strum_macros"
version = "0.25.3"
version = "0.26.0"
edition = "2018"
authors = ["Peter Glotfelty <peter.glotfelty@microsoft.com>"]
license = "MIT"
Expand All @@ -26,4 +26,4 @@ rustversion = "1.0"
syn = { version = "2.0", features = ["parsing", "extra-traits"] }

[dev-dependencies]
strum = { path = "../strum" }
strum = { path = "../strum", version= "0.25" }
2 changes: 1 addition & 1 deletion strum_macros/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn non_unit_variant_error() -> syn::Error {
syn::Error::new(
Span::call_site(),
"This macro only supports enums of strictly unit variants. Consider \
using it in conjunction with [`EnumDiscriminants`]"
using it in conjunction with [`EnumDiscriminants`]",
)
}

Expand Down
Loading

0 comments on commit 22606ef

Please sign in to comment.