Consider a struct with a hash map or tree map. I am trying to implement a function where values are inserted into the map as needed. A snippet goes as follows:
The problem here is similar in that you're creating a shared borrow over mystruct and trying to pass it a unique borrow over mystruct, and that can't be done because there's no way for both of those to safely exist at the same time.
What you can do is borrow parts of your struct separately rather than borrowing the whole thing, but this may mean you won't be able to use method syntax without creating some sort of additional wrapper type.
Another option is using interior mutability, but that usually has some overhead. Which is better probably depends on what you're trying to do.