Borrowing issue, trying to avoid redundancy

There are a few ways to deal with this:

  1. Organize your code (and method calls) to avoid having a conflicting borrow in scope. This is not an issue if all you have is immutable borrows, but obviously comes into play once a mutable borrow comes into play.
  2. Make use of the fact the compiler understands field disjointness. This means instead of requiring/borrow all of self, borrow individual fields and pass them around to, e.g., associated functions.
  3. Instead of using methods that require a borrow of self, use a macro to deduplicate callers but avoid a borrow of self at the same time.

I'd say #1 and/or #2 are preferable.

3 Likes