const-enum-tools-derive

Crates.ioconst-enum-tools-derive
lib.rsconst-enum-tools-derive
version0.4.3
sourcesrc
created_at2022-05-01 17:18:44.697686
updated_at2022-05-03 01:24:27.334798
descriptionTrait definitions for working with enums at compile time using macros.
homepage
repositoryhttps://github.com/tigergold59/const-enum-tools-derive
max_upload_size
id578676
size10,705
(TigerGold59)

documentation

README

const-enum-tools-derive

Derive macros for const-enum-tools.

#[derive(VariantCount)] on an enum adds to it a constant that has the number of variants of the enum.

#[derive(VariantList)] on an enum implements a method that gets the enum variant's index and an associated constant on it that has the name of all the variants. This allows you to iterate over the variants, as well as get the name of a variant you have as a string.

In cases where the discriminant of an enum variant corresponds to its index, .variant_index() will include an unsafe block that effectively copies the value's underlying bytes in order to clone them. This seems to be safe for now, but if any unsafety is found to leak through it will be removed. This optimization can be disabled by placing #[disallow_instance_bitcopy] on an enum variant or the enum itself.

Commit count: 11

cargo fmt