I've found example of how to implement PyIterProtocol in Rust.
use pyo3::prelude::*;
use pyo3::PyIterProtocol;
use pyo3::class::iter::IterNextOutput;
#[pyclass]
struct Iter {
count: usize
}
#[pyproto]
impl PyIterProtocol for Iter {
fn __next__(mut slf: PyRefMut<Self>) -> IterNextOutput<usize, &'static str> {
if slf.count < 5 {
slf.count += 1;
IterNextOutput::Yield(slf.count)
} else {
IterNextOutput::Return("Ended")
}
}
}
but I cannot figure out how to implement a container class that is iterable but is not a iterator itself. Essentially I want to be able to decompose my object in Python like
x, y, z = my_object