Crates.io | derive-enum-all-values |
lib.rs | derive-enum-all-values |
version | 0.1.0 |
source | src |
created_at | 2023-09-25 03:02:34.244841 |
updated_at | 2023-09-25 03:02:34.244841 |
description | A procedural derive macro which exposes a method named `all_values` that returns all defined values as a compile-time static. |
homepage | |
repository | https://github.com/Sewer56/derive-enum-all-values |
max_upload_size | |
id | 982317 |
size | 6,642 |
A procedural derive macro which exposes a method named all_values
that returns all defined values as a compile-time static.
Add derive_enum_all_values
to your Cargo.toml
:
[dependencies]
derive_enum_all_values = "0.1.0"
And then derive AllValues
for your enum:
use derive_enum_all_values::AllValues;
#[derive(AllValues)]
enum MyEnum {
Variant1,
Variant2,
// ... other variants ...
}
fn main() {
for variant in MyEnum::all_values() {
println!("{:?}", variant);
}
}
This macro generates the following code:
impl MyEnum {
pub fn all_values() -> &'static [MyEnum] {
&[MyEnum::Variant1, MyEnum::Variant2]
}
}
A static, compile time known array containing every enum value.
How to develop this project.
Clone this Repository:
# When cloning, make sure symlinks are enabled
git clone -c core.symlinks=true https://github.com/Sewer56/derive-enum-all-values.git
Install Rust:
Code
/VSCode
is the de-facto Rust development environment.
The following extensions are required:
The VSCode configuration in Reloaded projects (.vscode
) contain the following:
clippy
on Save.rustfmt
on Save.These configurations are in the .vscode
folder; and the tasks can be ran via Ctrl+Shift+P -> Run Task
.
The following is the expected file layout for your project:
.vscode/
src/
Cargo.toml
The src
folder should contains all source code for your project.
Cargo.toml
should be in the root of the project.
See CONTRIBUTING for guidance on how to contribute to this project.
Licensed under MIT.