Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
src/ | 25-Apr-2025 | - | 2,898 | 1,885 | ||
.cargo-checksum.json | D | 25-Apr-2025 | 2.3 KiB | 1 | 1 | |
Android.bp | D | 25-Apr-2025 | 1.3 KiB | 54 | 49 | |
Cargo.toml | D | 25-Apr-2025 | 1.3 KiB | 59 | 50 | |
LICENSE | D | 25-Apr-2025 | 1 KiB | 22 | 17 | |
METADATA | D | 25-Apr-2025 | 408 | 18 | 17 | |
MODULE_LICENSE_MIT | D | 25-Apr-2025 | 0 | |||
README.md | D | 25-Apr-2025 | 4.1 KiB | 83 | 63 | |
TEST_MAPPING | D | 25-Apr-2025 | 80 | 8 | 7 | |
cargo_embargo.json | D | 25-Apr-2025 | 122 | 10 | 9 |
README.md
1# Strum 2 3[](https://travis-ci.com/Peternator7/strum) 4[](https://ci.appveyor.com/project/Peternator7/strum) 5[](https://crates.io/crates/strum) 6[](https://docs.rs/strum) 7 8 9 10Strum is a set of macros and traits for working with enums and strings easier in Rust. 11 12# Compatibility 13 14Strum is currently compatible with versions of rustc >= 1.56.1. Pull Requests that improve compatibility with older 15versions are welcome. The project goal is to support a rust version for at least 2 years after release 16and even longer is preferred since this project changes slowly. 17 18# Including Strum in Your Project 19 20Import strum and strum_macros into your project by adding the following lines to your 21Cargo.toml. Strum_macros contains the macros needed to derive all the traits in Strum. 22 23```toml 24[dependencies] 25strum = "0.25" 26strum_macros = "0.25" 27 28# You can also use the "derive" feature, and import the macros directly from "strum" 29# strum = { version = "0.25", features = ["derive"] } 30``` 31 32# Strum Macros 33 34Strum has implemented the following macros: 35 36| Macro | Description | 37| --- | ----------- | 38| [EnumString] | Converts strings to enum variants based on their name. | 39| [Display] | Converts enum variants to strings | 40| [FromRepr] | Convert from an integer to an enum. | 41| [AsRefStr] | Implement `AsRef<str>` for `MyEnum` | 42| [IntoStaticStr] | Implements `From<MyEnum> for &'static str` on an enum | 43| [EnumVariantNames] | Adds an associated `VARIANTS` constant which is an array of discriminant names | 44| [EnumIter] | Creates a new type that iterates of the variants of an enum. | 45| [EnumProperty] | Add custom properties to enum variants. | 46| [EnumMessage] | Add a verbose message to an enum variant. | 47| [EnumDiscriminants] | Generate a new type with only the discriminant names. | 48| [EnumCount] | Add a constant `usize` equal to the number of variants. | 49 50# Contributing 51 52Thanks for your interest in contributing. The project is divided into 3 parts, the traits are in the 53`/strum` folder. The procedural macros are in the `/strum_macros` folder, and the integration tests are 54in `/strum_tests`. If you are adding additional features to `strum` or `strum_macros`, you should make sure 55to run the tests and add new integration tests to make sure the features work as expected. 56 57# Debugging 58 59To see the generated code, set the STRUM_DEBUG environment variable before compiling your code. 60`STRUM_DEBUG=1` will dump all of the generated code for every type. `STRUM_DEBUG=YourType` will 61only dump the code generated on a type named `YourType`. 62 63# Name 64 65Strum is short for STRing enUM because it's a library for augmenting enums with additional 66information through strings. 67 68Strumming is also a very whimsical motion, much like writing Rust code. 69 70[Macro-Renames]: https://github.com/Peternator7/strum/wiki/Macro-Renames 71[EnumString]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumString.html 72[Display]: https://docs.rs/strum_macros/0.25/strum_macros/derive.Display.html 73[AsRefStr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.AsRefStr.html 74[IntoStaticStr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.IntoStaticStr.html 75[EnumVariantNames]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumVariantNames.html 76[EnumIter]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumIter.html 77[EnumIs]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumIs.html 78[EnumProperty]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumProperty.html 79[EnumMessage]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumMessage.html 80[EnumDiscriminants]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumDiscriminants.html 81[EnumCount]: https://docs.rs/strum_macros/0.25/strum_macros/derive.EnumCount.html 82[FromRepr]: https://docs.rs/strum_macros/0.25/strum_macros/derive.FromRepr.html 83