What I'd like to be able to do is rely on existing containers to handle however they contain multiple items, and use their existing iterator to iterate over the container. I am aware of the existing questions:
- how-to-initialize-struct-fields-which-reference-each-other
- how-to-store-hashmap-and-its-values-iterator-in-the-same-struct
- struct-that-owns-some-data-and-a-reference-to-the-data
So, I've gathered that it's not possible in Rust to keep a reference to the container and its iterator in a custom struct, but I'm looking for a solution that would allow my custom struct to implement Iterator
to iterate over the container in my custom struct.
I've created the simplest example of what I'm trying to do:
- HashMap playground (edit: @Stargateur solution)
- Vec playground (edit: possible solution)
How can I modify UserStore
to support iteration? Or is this just not possible in Rust and need to essentially reimplement all the container functionality in UserStore
itself?