• Home
Name Date Size #Lines LOC

..--

src/04-Jul-2025-3,9002,642

.android-checksum.jsonD04-Jul-20253 KiB11

.cargo-checksum.jsonD04-Jul-20252.6 KiB11

Android.bpD04-Jul-20251.3 KiB5348

Cargo.tomlD04-Jul-20251.3 KiB5647

LICENSED04-Jul-20251 KiB2217

METADATAD04-Jul-2025408 1817

MODULE_LICENSE_MITD04-Jul-20250

README.mdD04-Jul-20254.6 KiB8968

TEST_MAPPINGD04-Jul-202580 87

cargo_embargo.jsonD04-Jul-2025148 1010

README.md

1# Strum
2
3[![Build Status](https://travis-ci.com/Peternator7/strum.svg?branch=master)](https://travis-ci.com/Peternator7/strum)
4[![Build status](https://ci.appveyor.com/api/projects/status/ji4f6n2m5lvu11xt?svg=true)](https://ci.appveyor.com/project/Peternator7/strum)
5[![Latest Version](https://img.shields.io/crates/v/strum.svg)](https://crates.io/crates/strum)
6[![Rust Documentation](https://docs.rs/strum/badge.svg)](https://docs.rs/strum)
7![Crates.io](https://img.shields.io/crates/l/strum)
8![Crates.io](https://img.shields.io/crates/d/strum)
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.66.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.27"
26strum_macros = "0.27"
27
28# You can also use the "derive" feature, and import the macros directly from "strum"
29# strum = { version = "0.27", 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| [EnumIter] | Creates a new type that iterates of the variants of an enum. |
44| [EnumProperty] | Add custom properties to enum variants. |
45| [EnumMessage] | Add a verbose message to an enum variant. |
46| [EnumDiscriminants] | Generate a new type with only the discriminant names. |
47| [EnumCount] | Add a constant `usize` equal to the number of variants. |
48| [VariantArray] | Adds an associated `VARIANTS` constant which is an array of all enum discriminants |
49| [VariantNames] | Adds an associated `VARIANTS` constant which is an array of discriminant names |
50| [EnumTable] | *Experimental*, creates a new type that stores an item of a specified type for each variant of the enum. |
51
52# Contributing
53
54Thanks for your interest in contributing. Bug fixes are always welcome. If you are interested in implementing or
55adding a macro, please open an issue first to discuss the feature. I have limited bandwidth to review new features.
56
57The project is divided into 3 parts, the traits are in the
58`/strum` folder. The procedural macros are in the `/strum_macros` folder, and the integration tests are
59in `/strum_tests`. If you are adding additional features to `strum` or `strum_macros`, you should make sure
60to run the tests and add new integration tests to make sure the features work as expected.
61
62# Debugging
63
64To see the generated code, set the STRUM_DEBUG environment variable before compiling your code.
65`STRUM_DEBUG=1` will dump all of the generated code for every type. `STRUM_DEBUG=YourType` will
66only dump the code generated on a type named `YourType`.
67
68# Name
69
70Strum is short for STRing enUM because it's a library for augmenting enums with additional
71information through strings.
72
73Strumming is also a very whimsical motion, much like writing Rust code.
74
75[EnumString]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumString.html
76[Display]: https://docs.rs/strum_macros/latest/strum_macros/derive.Display.html
77[AsRefStr]: https://docs.rs/strum_macros/latest/strum_macros/derive.AsRefStr.html
78[IntoStaticStr]: https://docs.rs/strum_macros/latest/strum_macros/derive.IntoStaticStr.html
79[EnumIter]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumIter.html
80[EnumIs]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumIs.html
81[EnumProperty]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumProperty.html
82[EnumMessage]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumMessage.html
83[EnumDiscriminants]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumDiscriminants.html
84[EnumCount]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumCount.html
85[FromRepr]: https://docs.rs/strum_macros/latest/strum_macros/derive.FromRepr.html
86[VariantArray]: https://docs.rs/strum_macros/latest/strum_macros/derive.VariantArray.html
87[VariantNames]: https://docs.rs/strum_macros/latest/strum_macros/derive.VariantNames.html
88[EnumTable]: https://docs.rs/strum_macros/latest/strum_macros/derive.EnumTable.html
89