I have a single "god object" struct which does all the processing. It used to have just lots of methods exposed as its API. I've decided to switch it to a set of "proxy" objects for public API. Each of those proxy objects contains reference to main struct, and many of its methods just execute now-hidden main struct methods. It allowed me to maintain a set of guarantees better, simplify error structure, etc, even if it follows OOP API look and feel, with rust being not the best tool for that.
I already implemented all the key parts. When reduced to basics, it looks like this. However, I have lots of proxy object types, split into several groups. For one of such groups, I'd like to generalize iterator implementation over proxy type it returns, since group is relatively large. But no matter how I try, I fail, likely due to not understanding all the limits and possibilities of lifetime notation.
To generalize over a set of proxies, I introduce a trait New
. Its only method doesn't do anything but create proxy structs from passed arguments, which are the same for proxies within the group I want to generalize over. But, I can't find a way to tie produced item to 'lend
lifetime of iterator. So far I've been running into "lifetime may not live long enough" (like in this example), trait method declaration incompatibility and a few other errors (tried GATs, GATs + implicit limits).
How do I proceed, to let iterator consume any proxy type which implements New
?