Skip to content
Discussion options

You must be logged in to vote

The two macros are quite different. #[pyclass] does a lot more than simply deriving FromPyObject and IntoPyObject.

In this case the former creates a class hierarchy with a base class Cuisine and "child" classes for each variant inheriting from it.

class Cuisine:
   Italian: Italian = ...
   ...
class Italian(Cuisine):
   ...

Each variant class then contains the fields of the variant.

The #[derive(IntoPyObject)] will not define any class at all. In your example it will simply match on the enum and forward to the IntoPyObject impl of the inner type, something like the following.

impl<'py> IntoPyObject<'py> for Cuisine {
    type Target = PyAny;
    type Output = Bound<'py, Self::Target>;
    

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by flotang-gtt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants