From c22c8ca7a93ecc333da2d21bbc3f5400c9e3c8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Glotfelty=20=F0=9F=9A=80?= Date: Wed, 5 Dec 2018 11:52:34 -0800 Subject: [PATCH] Updated docs and revved version numbers --- README.md | 27 +++++++++++++++++++++++++-- strum/Cargo.toml | 4 ++-- strum/src/lib.rs | 32 +++++++++++++++++++++++++++++++- strum_macros/Cargo.toml | 2 +- strum_tests/Cargo.toml | 2 +- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8ae042d..9b311d4 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ Cargo.toml. Strum_macros contains the macros needed to derive all the traits in ```toml [dependencies] -strum = "0.11.0" -strum_macros = "0.11.0" +strum = "0.12.0" +strum_macros = "0.12.0" ``` And add these lines to the root of your project, either lib.rs or main.rs. @@ -385,6 +385,29 @@ Strum has implemented the following macros: also for given `enum MyEnum` generates `const MYENUM_COUNT: usize` which gives the same value as `strum::EnumCount` (which is usefull for array sizes, etc.). + ```rust + extern crate strum; + #[macro_use] extern crate strum_macros; + + #[derive(Debug, EnumCount, EnumIter)] + enum Week { + Sunday, + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + } + + #[test] + fn main() { + assert_eq!(7, Week::count()); + assert_eq!(Week::count(), WEEK_COUNT); + assert_eq!(Week::iter().count(), WEEK_COUNT); + } + ``` + # Additional Attributes Strum supports several custom attributes to modify the generated code. At the enum level, the diff --git a/strum/Cargo.toml b/strum/Cargo.toml index 9dfb61f..2c1e154 100644 --- a/strum/Cargo.toml +++ b/strum/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum" -version = "0.11.0" +version = "0.12.0" authors = ["Peter Glotfelty "] license = "MIT" @@ -13,7 +13,7 @@ homepage = "https://github.com/Peternator7/strum" readme = "../README.md" [dev-dependencies] -strum_macros = { path = "../strum_macros", version = "0.11.0" } +strum_macros = { path = "../strum_macros", version = "0.12.0" } [badges] travis-ci = { repository = "Peternator7/strum" } \ No newline at end of file diff --git a/strum/src/lib.rs b/strum/src/lib.rs index 34450ad..0ff91f1 100644 --- a/strum/src/lib.rs +++ b/strum/src/lib.rs @@ -372,6 +372,35 @@ //! assert_eq!(MyVariants::Variant0, MyEnum::Variant0(true).into()); //! } //! ``` +//! +//! 8. `EnumCount`: for a given enum generates implementation of `strum::EnumCount`, +//! which returns number of variants via `strum::EnumCount::count` method, +//! also for given `enum MyEnum` generates `const MYENUM_COUNT: usize` +//! which gives the same value as `strum::EnumCount` (which is usefull for array sizes, etc.). +//! +//! ```rust +//! extern crate strum; +//! #[macro_use] extern crate strum_macros; +//! +//! use strum::{IntoEnumIterator, EnumCount}; +//! +//! #[derive(Debug, EnumCount, EnumIter)] +//! enum Week { +//! Sunday, +//! Monday, +//! Tuesday, +//! Wednesday, +//! Thursday, +//! Friday, +//! Saturday, +//! } +//! +//! fn main() { +//! assert_eq!(7, Week::count()); +//! assert_eq!(Week::count(), WEEK_COUNT); +//! assert_eq!(Week::iter().count(), WEEK_COUNT); +//! } +//! ``` //! //! # Additional Attributes //! @@ -670,7 +699,8 @@ where fn as_static(&self) -> &'static T; } -/// Number of variants in Enum +/// A trait for capturing the number of variants in Enum. This trait can be autoderived by +/// `strum_macros`. pub trait EnumCount { fn count() -> usize; } diff --git a/strum_macros/Cargo.toml b/strum_macros/Cargo.toml index c25b3aa..942b54b 100644 --- a/strum_macros/Cargo.toml +++ b/strum_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum_macros" -version = "0.11.0" +version = "0.12.0" authors = ["Peter Glotfelty "] license = "MIT" diff --git a/strum_tests/Cargo.toml b/strum_tests/Cargo.toml index 5075c4f..f9b9fed 100644 --- a/strum_tests/Cargo.toml +++ b/strum_tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strum_tests" -version = "0.11.0" +version = "0.12.0" authors = ["Peter Glotfelty "] [dependencies]