1
0
mirror of https://github.com/danog/strum.git synced 2024-11-26 20:14:40 +01:00

Updated docs and revved version numbers

This commit is contained in:
Peter Glotfelty 🚀 2018-12-05 11:52:34 -08:00
parent b66f15edb5
commit c22c8ca7a9
5 changed files with 60 additions and 7 deletions

View File

@ -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

View File

@ -1,6 +1,6 @@
[package]
name = "strum"
version = "0.11.0"
version = "0.12.0"
authors = ["Peter Glotfelty <peglotfe@microsoft.com>"]
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" }

View File

@ -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;
}

View File

@ -1,6 +1,6 @@
[package]
name = "strum_macros"
version = "0.11.0"
version = "0.12.0"
authors = ["Peter Glotfelty <peglotfe@microsoft.com>"]
license = "MIT"

View File

@ -1,6 +1,6 @@
[package]
name = "strum_tests"
version = "0.11.0"
version = "0.12.0"
authors = ["Peter Glotfelty <peglotfe@microsoft.com>"]
[dependencies]