Skip to content
Discussion options

You must be logged in to vote

Implemeting Into<PyClassInitializer> is not going to help here. You could implement PyClass for StrOrIntIter, forwarding the __iter__ and __next__ methods to the inner types.

However, if StrOrIntIter is only needed for the benefit of Python code, I think it would be easier to have the iter return Py<PyAny>, without a wrapper type, somewhat like this:

// in wrapper.rs - I don't want to pollute core.rs with pyo3 context
impl Wrapper {
    // fns...

    fn iter(&self, py: Python<'_>) -> Result<Py<PyAny>, PyErr> {
        match &self.inner {
            WrapperInner::Str(core) => {
                IterStr {
                    inner: core.members.clone().into_iter(),
                }.into_py(

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@StuartHadfield
Comment options

@birkenfeld
Comment options

Answer selected by StuartHadfield
Comment options

You must be logged in to vote
1 reply
@StuartHadfield
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants