I think I've got a special case where I'm trying to borrow the same variable both as immutable and mutable at the same time due to a kind of circular reference. I know this is not a good programming practice, but in the context I'm working with it makes sense.
An example of the code is here:
The real scenario is a bit different as the MainLoopContext is being sent down the Scene object through that process function because I have an array of systems that use that MainLoopContext object for various computations, but that context lives outside the library and it can be defined by the end user in his own application. Thus it's implemented as a generic.
The problem is that MainLoopContext has to hold a reference to the Scene object because that is also used by user-defined systems.
Is there another way around this? Thanks in advance!
Split your context in two, 1 containing part containing the scene, the other part containing all other data nneded for process then pass the other data to process directly.
Because process is a method that then iterates on an array that lives in an object contained in the Scene (it's called World). And this World object that has all the System instances then calls the process of each system.
So I end up with a process method somewhere that needs the context to perform its duties and not the other way around. I don't know if this makes sense
It might be interesting to create an example with somewhat closer structure to what your describe. I might have a sufficiently similar example that a shared solution would be possible.