If I'm using pyo3 to create a module called Test and I have some rust code like this
pub enum Event{
A(u32),
B(u32),
...
}
const X: u32 = 0;
How can I expose these to Python, e.g. as Test.Event.A and Test.X?
i dont know :)
maybe class properties? you can create class and expose some properties or static methods
technically, i think it is possible to bridge rust enums to a python enums, at least some subset, but that will require time
Hi @fafhrd91, because my project needs to export Rust enum to Python enum, I'm wondering if it makes sense that turn Rust enum to PyTuple that already implemented in PyO3, that according to Python document says the semantics of Python enum API resemble namedtuple?
Or I just make it as class...which seems also work as you commented.
@snowmantw I don鈥檛 maintain this library anymore. @konstin is maintainer
@konstin Can you create a small, complete example of how to make bindings that pass python enum.Enum to rust and back again? I keep getting errors each time I try to do it, and I'm the point where I'm passing u8 back and forth just because it's easier, but it really breaks the mental model to do so.
Most helpful comment
@konstin Can you create a small, complete example of how to make bindings that pass python enum.Enum to rust and back again? I keep getting errors each time I try to do it, and I'm the point where I'm passing
u8back and forth just because it's easier, but it really breaks the mental model to do so.