Hello there,
I feel a bit embarrassed by my apparent lack of understanding of what is probably a very simple borrow checking issue.
I have this playground that mimics a situation I encountered in my project:
The gist of it is: I have a mutable struct in my main:
let mut spi = Spidev::new()
I can easily pass that for a method call to a local
function via
full_duplex(&mut spi);
with the signature being
fn full_duplex(spi: &mut Spidev)
My understanding according to Mutability is that the parameter spi is a mutable reference. Which makes sense - we want to work with spi and mutate it, but not rebind the name spi to anything else.
But then I introcude an intermediate function work:
fn work(mut spi: &mut Spidev)
{
loop {
full_duplex(&mut spi);
if spi.counter % 10 == 0 {
break;
}
}
}
And here the mut in front of spi is the culprit. How come I need this? I do not re-bind spi (to the best of my knowledge.
What am I missing? Waiting to slap my head.