So recently i've stumbled upon a pattern in rust and i want to make some optimizations on it so that i can simplify my codes. Here's the psuedocode.
for foo in fooIter {
for bar in foo.iter() {
// do something on the bar.
}
}
Her BarIter borrows foo so that it can yield some data structures that are constructed from the borrowed inner fields of foo because foo is a container.
What i'm trying to achieve here is to merge these two loops into one for something like.
fooIter.transform_into_other_iter_from_foo()
Here foo must be an owned type not an reference to some other types sadly.
Another constrait is that FooIter is not a collection of foos instead it only construcst a foo and does not hold it because its len cannot be determined.
My question is how to merge this two loops. Because i got a struct capable of yielding FooIter and it's really helpful if i can also yield BarIter or some other Iters based on this method which can help me save a lot works from writing this burdonsome pattern. Or is it simply unachievable? Thanks