Skip to main content

drop_cvec_pycapsule

Function drop_cvec_pycapsule 

Source
pub fn drop_cvec_pycapsule(capsule: &Bound<'_, PyAny>)
Expand description

Drops a PyCapsule containing a CVec structure.

This function safely extracts and drops the CVec instance encapsulated within a PyCapsule object. It is intended for cleaning up after the Data instances have been transferred into Python (e.g. via capsule_to_list) and are no longer needed.

§Capsule type contract

Must only be called on capsules that contain a CVec (pointer to Vec<DataFFI>). Never pass a capsule from data_to_pycapsule here: when that function returns a single-Data capsule (e.g. for Data::Custom), the pointer is not a CVec, and calling this would be undefined behavior.

§Panics

Panics if the capsule cannot be downcast to a PyCapsule, indicating a type mismatch or improper capsule handling.

This function involves raw pointer dereferencing and manual memory management. The caller must ensure the PyCapsule contains a valid CVec pointer.