When I was a Rust beginner I had a hard time with this, and now that I’m competent I still run into the “disjoint field borrow” problem on a regular basis.
Of course I know all the tricks and workarounds, and I use them to fix the problem and move on with my life, but it never feels nice.
I’ve often used both the sub-struct and free function workarounds. I know about view structs but I consider them too heavy-weight. If there was an easier way to create view structs (perhaps a macro?) I think they would be a good workaround.
I’ve internalized the workarounds enough so that I don’t directly run into this problem very often (i.e. I rarely get actual compile errors), but it does add extra friction when writing code (because it essentially requires some unnatural refactoring to workaround what feels like a bug in the compiler, even though I know it’s not a bug).
The most annoying thing is when working with Pinned types (like Futures), because the Pin API requires you to use methods to access the fields (you cannot access fields directly), but that immediately runs into the disjoint field borrow problem.
And unlike most situations, you cannot refactor it using sub-structs or free functions, so in some situations you’re forced to do really hacky things like unsafely borrow the entire struct and then carefully avoid mutating/moving certain fields:
View structs (which have been specialized to work with Pin types) could be a good solution for this.
I would love to have a general solution for disjoint field borrowing, but I understand it’s an extremely tricky thing to solve, with a lot of design space to explore. So I think it’s a good long-term goal, but I don’t expect it to happen anytime soon. And it may never happen, we may be stuck with workarounds forever.
Regardless of what the outcome is, I trust the Rust lang team will make the right decision. They’ve definitely earned my respect (and then some) over the years. Thank you for working so hard and achieving so much.