Macro anchor::klipper_enumeration
klipper_enumeration!() { /* proc-macro */ }
Expand description
Creates a Klipper compatible enumeration
The general syntax can be seen by the following example:
klipper_enumeration! {
#[derive(Debug)]
#[klipper_enumeration(name = "pin", rename_all = "UPPERCASE")]
enum Pins {
Range(PA, 0, 15),
Range(PB, 0, 15),
AdcTemperature,
}
}
The item must always be an enum
.
Variants can either be directly specified, or a range can be requested. For ranges, the format is:
Range(Prefix, start, count)
This will generate count
items named Prefix{start+i}
.
Variants can be enabled or disabled using standard #[cfg(feature...)]
feature flags.
The top item and the enumerations can accept parameters. These can be given using the
#[klipper_enumeration(opts)]
attribute. For the top level item, opts
can take the following
forms:
name = "a_name"
: An override name of the enumeration seen in the dictionaryrename_all = "UPPERCASE|lowercase|snake_case"
: a default renaming option for all variants
For each variant entry, the following options are available:
rename
: An override name of this variant in the dictionary. For range variants, all values are renamed.
All values will be automatically mapped to IDs. Implementations of TryFrom<u{8, 16, 32, 64, size>
are generated automatically, along with implementations of From<Self> for u{8, 16, 32, 64, usize}
. The number of bits in these generated functions is determining by the number of
variants. E.g. if the enum has more than 255 variants, the u8
functions are not generated.