Replies: 2 comments 5 replies
-
|
I think you'll need to provide a more complete minimal example. At the moment it's hard to follow what's happening on your end. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
OK a playground link is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=13acb058ec76ae55db9b644cd2958698 You can use this to verify that the test at the bottom fails becuase this is no implementation of a struct D1 adding D2. If you export D1 and D2 to Python with PyO3 and run in Python: a = D1(3.0)
b = D2(2.5)
c = a + b # works in Python returns a D1.
c = b + a # works in Python returns a D2. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have defined two structs in rust, which I can use in Python via
#[pyclass], for minimalist example:I have performed operator overloading on these for many operations for their same struct ops and crossing with f64.
I.e. in
rustthe following work:D1 + D1,D1 + f64,D2 + D2,D2 + f64.In
rustthe following does not workD1 + D2due tono implementation for D1 + D2. This is as designed.In Python if I add
D1 + D2it seems to be converting one of them to float and returning a valid result.Where is this conversion taking place and how do I avoid it?
For
D1in#[pymethods]I have defined:I am wondering if
FromPyObjectis specifically converting aD2tof64since there is a valid__float__pymethod available on bothD1andD2?Is it possible to specifically prevent this? Am I wrong about the location of the conversion? Do I need to expand all of my match cases and my enum to include all 3 types: D1, D2 and f64?
Beta Was this translation helpful? Give feedback.
All reactions