So, I have this code in <edition = "2018">
, which brings in NLL support, and so I presumed that code that used to look like this:
let app_ref = &mut self.app;
let ws_ref = &mut self.window_size;
self.gl.draw(render_args.viewport(), |c, gl| {
//mutably and immutably use app_ref and ws_ref
});
to something that I thought that the compiler could manage...
self.gl.draw(render_args.viewport(), |c, gl| {
//Use both here again
});
I presumed that the compiler could manage, because there were separate components of self
being used, but this unfortunately ends up in a bit of a pickle...
error[E0501]: cannot borrow `self.gl` as mutable because previous closure requires unique access
error[E0500]: closure requires unique access to `self` but it is already borrowed
and upon further modification to appease the compiler, I end up at
error[E0502]: cannot borrow `self.gl` as mutable because it is also borrowed as immutable
error[E0502]: cannot borrow `self` as immutable because it is also borrowed as mutable
Great... it's misunderstood me for a troublemaker who would attempt to hold both a mutable reference and an immutable reference, and use them pfft. I mean, clearly it works in the first example, so why not in the second?
Finished dev [unoptimized + debuginfo] target(s) in 3.87s
(Output of compiling the first example)
Ps., for those of you wondering, I'm using piston
.