pyo3::impl_::pymethods

Function _call_traverse

Source
#[doc(hidden)] pub unsafe fn _call_traverse<T>(
    slf: *mut PyObject,
    impl_: fn(_: &T, _: PyVisit<'_>) -> Result<(), PyTraverseError>,
    visit: visitproc,
    arg: *mut c_void,
    current_traverse: traverseproc,
) -> c_int
where T: PyClass,
Expand description

Calls an implementation of traverse for tp_traverse

NB cannot accept 'static visitor, this is a sanity check below:

use pyo3::prelude::*;
use pyo3::pyclass::{PyTraverseError, PyVisit};

#[pyclass]
struct Foo;

#[pymethods]
impl Foo {
    fn __traverse__(&self, _visit: PyVisit<'static>) -> Result<(), PyTraverseError> {
        Ok(())
    }
}

Elided lifetime should compile ok:

use pyo3::prelude::*;
use pyo3::pyclass::{PyTraverseError, PyVisit};

#[pyclass]
struct Foo;

#[pymethods]
impl Foo {
    fn __traverse__(&self, _visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
        Ok(())
    }
}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here