Skip to main content

cast_non_null_function_argument

Function cast_non_null_function_argument 

Source
pub unsafe fn cast_non_null_function_argument<'py>(
    py: Python<'py>,
    raw_arg: NonNull<PyObject>,
) -> Borrowed<'py, 'py, PyAny>
Expand description

Cast a NonNull<ffi::PyObject> to a PyArg. This is used to access safer PyO3 APIs with the assumption that the borrowed argument is valid for the lifetime 'py.

This has the effect of limiting the lifetime of function arguments to 'py, i.e. avoiding accidentally creating 'static lifetimes from raw pointers.

§Safety

  • raw_arg must be a valid NonNull<ffi::PyObject> for the lifetime 'py.
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here