• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

src/25-Apr-2025-2,8981,885

.cargo-checksum.jsonD25-Apr-20252.3 KiB11

Android.bpD25-Apr-20251.3 KiB5449

Cargo.tomlD25-Apr-20251.3 KiB5950

LICENSED25-Apr-20251 KiB2217

METADATAD25-Apr-2025408 1817

MODULE_LICENSE_MITD25-Apr-20250

README.mdD25-Apr-20254.1 KiB8363

TEST_MAPPINGD25-Apr-202580 87

cargo_embargo.jsonD25-Apr-2025122 109

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