I’m rewriting a C++ plugin that provides requests and JSON functionality. One of the functions is JsonAppend, which appends objects or arrays to one another. It takes an
a and a
b which are both slab-style “pointers” to a global pool of
b come in as integers which are then used to look up a JSON value in a HashMap - simple right?
The value that
a points to should be acquired as mutable, because it’s being appended to. The value that
b points to doesn’t need to be mutable because it’s being merged with
Here’s the corresponding C++ code:
And here’s my non-working Rust implementation of that function:
With the issue being that
self.json_nodes is being borrowed twice.
Now, I thought of cloning the node pool but that seems wasteful, especially since the pool could get quite big and doing that on serialisation functions that may be called very frequently (users use this library for structured logging, so speed is something I’m focused on).
Would appreciate any help! I thought I had mastered the borrow checker but apparently not…