derive-enum-all-values

Crates.ioderive-enum-all-values
lib.rsderive-enum-all-values
version0.1.0
sourcesrc
created_at2023-09-25 03:02:34.244841
updated_at2023-09-25 03:02:34.244841
descriptionA procedural derive macro which exposes a method named `all_values` that returns all defined values as a compile-time static.
homepage
repositoryhttps://github.com/Sewer56/derive-enum-all-values
max_upload_size
id982317
size6,642
Sewer. (Sewer56)

documentation

README

derive-enum-all-values

Crates.io Docs.rs CI

About

A procedural derive macro which exposes a method named all_values that returns all defined values as a compile-time static.

Usage

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.

Development

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:

Visual Studio Code Integration

Code/VSCode is the de-facto Rust development environment.

The following extensions are required:

The VSCode configuration in Reloaded projects (.vscode) contain the following:

  • Run Rust linter clippy on Save.
  • Run code format rustfmt on Save.
  • Tasks for common operations (generate documentation, active CI/CD etc.).

These configurations are in the .vscode folder; and the tasks can be ran via Ctrl+Shift+P -> Run Task.

File Layout

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.

Contributing

See CONTRIBUTING for guidance on how to contribute to this project.

License

Licensed under MIT.

Commit count: 7

cargo fmt