I had been learning Rust recently.
I stumbled across the following code:
pub fn to_bytes(values: &[u32]) -> Vec<u8> {
for &(mut value) in values {
//...
}
}
I do not understand the &
in the for
loop. What exactly is happening here?
I figured out that if you iterate over a vector, using a for loop, you get a reference (found here):
let v = vec![1, 2, 3];
for value in &v {
// value is a reference
}
Then why do I need another &
in the first snipped?