`IntoIter` type when the `into_iter` is a bunch of `values`, `map`, `flatten` etc. calls?

⚓ Rust    📅 2025-09-27    👤 surdeus    👁️ 8      

surdeus

Warning

This post was published 34 days ago. The information described in this article may have changed.

I'm trying to implement IntoIterator for my type and I'm not sure how to specify the associated type IntoIter.

The into_iter function body looks like this:

self.set.values().map(TraitPreds::iter).flatten()

So the concrete iterator type is a complex type and I don't want to figure it out myself. Normally in a non-trait method I'd use impl Iterator<Item = ...> + '_, but that's not valid when specifying associated types.

I'd normally not care and just implement non-trait into_iter/iters and use them explicitly in the loops, but I have code that iterates the previous version of this type currently and I'm trying to be somewhat backwards compatible to keep the diff small.

Is there a trick to this? Do I have to manually figure out the concrete iterator type here?

4 posts - 2 participants

Read full topic

🏷️ Rust_feed