pub fn data_to_pycapsule(py: Python<'_>, data: Data) -> Py<PyAny>Expand description
Creates a Python PyCapsule object containing a Rust Data instance.
This function takes ownership of the Data instance and encapsulates it within
a PyCapsule object, allowing the Rust data to be passed into the Python runtime.
§Panics
This function panics if the PyCapsule creation fails, which may occur if
there are issues with memory allocation or if the Data instance cannot be
properly encapsulated.
§Safety
This function is safe as long as the Data instance does not violate Rust’s
safety guarantees (e.g., no invalid memory access). Users of the
PyCapsule in Python must ensure they understand how to extract and use the
encapsulated Data safely, especially when converting the capsule back to a
Rust data structure.