I understand, why this can not work. The documentation of Ref<T> says, that the data can be accessed as long as it is in scope. In my example, it will drop in the enumerate() function, so I an not able to call the inner enumerate() method.
Is there some kind of workaround for this? I already tried everything I could think of including creating a new iterator, which owns the Rc, or the Ref, but nothing worked so far.
The main problem is, that I can not return any references from the Ref in a function.
Conceptually, you need to use Ref::map there, to make the iterator hold the lock on the data. However, map works only with plain references. So, if you are fine with exposing &[String], you can do this:
Good to see that people are finding that method useful. I was initially somewhat opposed to it out of concern that people would soon encounter situations where they need to individually borrow more than 2 fields (since this cannot be achieved with the 2-reference function alone), but if a decent number of people are satisfied with this limitation, that’s great.