Skip to main content

pyo3/impl_/pyclass/
traverse.rs

1use crate::{
2    gc::{PyTraverseError, PyVisit},
3    impl_::pyclass::PyClassImplCollector,
4};
5
6/// Autoref specialization point for `__traverse__` implementations.
7///
8/// Type parameter `T` is necessary to make the trait local to the implementing crate.
9pub trait PyClassTraverse<T> {
10    /// `self` is used for autoref specialization of `PyClassImplCollector` and `&PyClassImplCollector`.
11    /// `this` is the instance of the class being traversed.
12    fn __traverse__(self, this: &T, visit: PyVisit<'_>) -> Result<(), PyTraverseError>;
13}
14
15/// Fallback implementation for types without a `__traverse__` pymethod.
16impl<T> PyClassTraverse<T> for &'_ PyClassImplCollector<T> {
17    fn __traverse__(self, _this: &T, _visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
18        Ok(())
19    }
20}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here