rework complex enum field conversion#4694
Conversation
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks! Agreed this could use a refactor, probably that's easier after we remove ToPyObject and other backwards-compatibility arms from the #[pyo3(get)] code.
|
Hello, Thanks for this implementation. Just two questions:
I'm trying to mimic the behavior in Python and in Rust of an Expression builder, and as these can become complex, it makes sense in my use-case to have them be clonable and enable equality checks. Thanks Edit: My use case currently requires me to define the enum as follows. Would it be possible for PyO3 to automatically convert the #[derive(Debug)]
#[cfg_attr(not(feature = "python"), Clone, PartialEq)]
pub enum VectorExpr {
Fixed {
x: f64,
y: f64,
z: f64,
}, // Unitless vector, for arbitrary computations
Radius(StateSpec),
Velocity(StateSpec),
OrbitalMomentum(StateSpec),
EccentricityVector(StateSpec),
#[cfg(not(feature = "python"))]
CrossProduct {
a: Box<Self>,
b: Box<Self>,
},
#[cfg(feature = "python")]
CrossProduct {
a: Py<VectorExpr>,
b: Py<VectorExpr>,
},
} |
|
It can't be For similar reasons As for |
|
Understood, thanks for the details. Do you have any recommendations on how I should approach this enum I'm working on? |
This reworks the complex enum field conversion to use
IntoPyObjecteither by reference if available, or together withCloneif not.I think in the future we should probably rework complex enums to make them use of the same infrastructure we already have for
#[pyo3(get)].Closes #4216
Xref #4651