Debian Codegraph @

third_party/rust/strum/README.md

raw
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
10 Strum is a set of macros and traits for working with enums and strings easier in Rust.
11
12 # Compatibility
13
14 Strum is currently compatible with versions of rustc >= 1.66.1. Pull Requests that improve compatibility with older
15 versions are welcome. The project goal is to support a rust version for at least 2 years after release
16 and even longer is preferred since this project changes slowly.
17
18 # Including Strum in Your Project
19
20 Import strum and strum_macros into your project by adding the following lines to your
21 Cargo.toml. Strum_macros contains the macros needed to derive all the traits in Strum.
22
23 ```toml
24 [dependencies]
25 strum = "0.27"
26 strum_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
34 Strum 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
54 Thanks for your interest in contributing. Bug fixes are always welcome. If you are interested in implementing or
55 adding a macro, please open an issue first to discuss the feature. I have limited bandwidth to review new features.
56
57 The 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
59 in `/strum_tests`. If you are adding additional features to `strum` or `strum_macros`, you should make sure
60 to run the tests and add new integration tests to make sure the features work as expected.
61
62 # Debugging
63
64 To 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
66 only dump the code generated on a type named `YourType`.
67
68 # Name
69
70 Strum is short for STRing enUM because it's a library for augmenting enums with additional
71 information through strings.
72
73 Strumming 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