pub trait AsPyPointer {
    fn as_ptr(&self) -> *mut PyObject;
Expand description

This trait represents that we can do zero-cost conversion from the object to a FFI pointer.

This trait is implemented for types that internally wrap a pointer to a Python object.


use pyo3::{prelude::*, AsPyPointer};
Python::with_gil(|py| {
    let dict = pyo3::types::PyDict::new(py);
    // All native object wrappers implement AsPyPointer!!!
    assert_ne!(dict.as_ptr(), std::ptr::null_mut());

Required methods

Retrieves the underlying FFI pointer (as a borrowed pointer).

Implementations on Foreign Types

Convert None into a null pointer.