Inspecting and working with custom Python objects
Technically, everything in Python is an object. The Python dictionary that we worked on within the previous section is an object, so we have already managed Python objects. However, as we know, Python enables us to build custom objects. In this section, we will get our Rust function to accept a custom Python class that will have number
and numbers
attributes. To achieve this, we must carry out the following steps:
- Create an object that passes itself into our Rust interface.
- Acquire the Python global interpreter lock (GIL) within our Rust code to create a
PyDict
struct. - Add the custom object's attributes to our newly created
PyDict
struct. - Set the attributes of the custom object to the results of our
run_config
function.
Creating an object for our Rust interface
We start our journey by setting up our interface object, as follows:
- We house our object that will pass itself into our Rust code in...