Macro rigetti_pyo3::py_wrap_simple_enum
source · macro_rules! py_wrap_simple_enum { ( $(#[$meta: meta])* $name: ident($rs_inner: ident) $(as $py_class: literal)? { $($variant_name: ident),+ } ) => { ... }; ( $(#[$meta: meta])* $name: ident($rs_inner: ident) $(as $py_class: literal)? { $($variant_name: ident as $variant_alias: ident),+ } ) => { ... }; }
Expand description
Wrap an enum containing only unit variants.
Implements
- Conversion between Rust and Python types (also converting from references to each)
§Macro Inputs
$variant_name: comma-separated list of variant names on the Rust enum. Required because there is no way to do reflection to programmatically find them.$variant_alias: used in conjunction with$variant_nameas the Python enum member name when it should be named differently, useful in cases when the enum member name is not a valid python identifier. If one variant uses an alias, they all must, even if the alias is the same as the name.- See also
py_wrap_type.
§Example
use rigetti_pyo3::py_wrap_simple_enum;
#[derive(Copy, Clone)]
pub enum RustEnum {
Foo,
Bar,
}
py_wrap_simple_enum! {
PyEnum(RustEnum) {
Foo,
Bar
}
}
py_wrap_simple_enum! {
PyEnumAliased(RustEnum) {
Foo as FOO,
Bar as Bar
}
}