Flat_map on an iterator of Results

This is a very common way offramp from learning rust; you're not alone.

I'd strongly suggest that you just not worry about it for a while. Just add a few .to_owned()s in a few places, or collect into Vec<_>s if iterators are being awkward. It's fine.

You can always come back later, once things are at least working, and improve any hotspots. But one of the magical things about Rust is that it's pretty damn fast even without doing heroic efforts. (With a reasonable allocator, copying a reasonable-size string just isn't that big a deal.)

One other thing you might be hitting: everyone would love to have an impl Iterator<Item = Result<T, E>>Result<impl Iterator<Item = T>, E>. But it's impossible to do that without allocation: if it's lazy it can't look into the future to see that there will be an error, and if it's non-allocating it has nowhere to store all the Ts it might need to return if there's no E. So you might just be in a place where trying iterator adapters is never going to work as perfectly as you'd like.