I have a locked a
with a vecotr of B
struct inside. I'd like to filter a.b
without cloning B
struct. Is it possible in Rust?
use std::sync::{Arc, Mutex};#[derive(Debug)]struct B { n: i64,}#[derive(Debug)]struct A { b: Vec<B>}fn main() { let arc_a = Arc::new(Mutex::new(A { b: vec![ B { n: 1 }, B { n: 2 }, B { n: 3 }, B { n: 4 }, ] })); let mut a = arc_a.lock().unwrap(); a.b = a.b.into_iter().filter(|b| b.n % 2 == 1).collect(); println!("{:?}", a);}
In the code example above I have an error error[E0507]: cannot move out of dereference of MutexGuard<'_, A>
. Are there ways to solve this challenge?