Skip to main content

cast_function_argument

Function cast_function_argument 

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

Cast a raw *mut 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 *mut ffi::PyObject for the lifetime 'py.
  • raw_arg must not be NULL.
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here