I'm trying to figure out the best way to handle some nested mutable changes. I've got the following code that mimicks the issue I'm running into:
use std::collections::HashMap;
use circular_buffer::CircularBuffer;
#[tokio::main]
async fn main() {
let mut hash:HashMap<u8, CircularBuffer<200, f32>> = HashMap::new();
for idx in 0..10 {
let mut buffer = CircularBuffer::<200, f32>::new();
buffer.push_front(14.0 * idx as f32 + 2.0);
buffer.push_front(19.4 * idx as f32 + 4.19);
hash.insert(idx, buffer);
}
tokio::spawn(async move {
for (key, mut value) in hash {
println!("key: {}, buffer_length: {}", key, value.len());
let mut first = value[0];
first = 24.0 * key as f32;
}
for (key, mut value) in hash {
println!("key: {}, buffer_length: {}", key, value.len());
let mut first = value[0];
println!("\tFirst: {}", first);
}
});
}
You can ignore the data entered into the hash -- I'm just putting dummy data there. In reality, it's a custom struct, and I need to modify items inside the structs. The code below gives the exact same compiler error, so I think the example is sufficient.
What's the best way to iterate through hash so that I can modify the data as needed? The compiler suggests adding an & to the beginning of hash, but that doesn't really resolve the issue, either. I'm probably looking at this incorrectly. Suggestions would be very much appreciated.

&mutinstead of&?