So I have this code:
use std::sync::{Arc, Mutex};
fn main() {
let array = vec!("test", "work", "please");
let test = Arc::new(Mutex::new(array));
let getter = test.lock().unwrap();
println!("{:?}", getter);
for item in getter {
println!("{}", item);
}
}
it throws an error saying:
error[E0277]: `MutexGuard<'_, Vec<&str>>` is not an iterator
--> src/main.rs:11:17
|
11 | for item in getter {
| ^^^^^^ `MutexGuard<'_, Vec<&str>>` is not an iterator
|
= help: the trait `Iterator` is not implemented for `MutexGuard<'_, Vec<&str>>`
= note: required because of the requirements on the impl of `IntoIterator` for `MutexGuard<'_, Vec<&str>>`
Which, okay fine. But I am able to do let getter = test.lock().unwrap().len(); and that gets the length correctly. So why does it know its an array in the second case but not the first?