Skip to main content

extract_pyclass_ref_trusted

Function extract_pyclass_ref_trusted 

Source
pub unsafe fn extract_pyclass_ref_trusted<'a, 'holder, T: PyClass>(
    obj: Borrowed<'a, '_, PyAny>,
    holder: &'holder mut Option<PyClassGuard<'a, T>>,
) -> PyResult<&'holder T>
Expand description

Trusted variant of extract_pyclass_ref: performs an unchecked cast for extension-type slot receivers where CPython guarantees the receiver type.

This is valid when called from generated slot wrappers installed on a specific extension type, because CPython’s slot dispatch contract ensures the receiver is an instance of that type (or a compatible subtype) before invoking the slot.

§Safety

The caller must ensure that obj is an instance of T. This invariant is upheld by CPython when dispatching through type slots.

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here