Artificial intelligent assistant

ArcとVecのmutableエラー'cannot borrow as mutable'について Vecthread cannot borrow as mutable (E0596)mutmut use std::vec::Vec; use std::sync::Arc; use std::{thread,time}; fn main() { let arc: Arc<Vec<i32>> = Arc::new(Vec::new()); let mut _arc = Arc::clone(&arc); thread::spawn(move || { for x in 1..=10 { _arc.push(x); } }); thread::sleep(time::Duration::from_secs(3)); arc.iter().map(|n| println!("{:?}",n)); } error[E0596]: cannot borrow data in a `&` reference as mutable --> src/main.rs:11:13 | 11 | _arc.push(x); | ^^^^ cannot borrow as mutable

`Arc``Arc``RwLock``Mutex``RwLock`


use std::sync::{Arc, RwLock};
use std::vec::Vec;
use std::{thread, time};

fn main() {
let arc = Arc::new(RwLock::new(Vec::new())); // Arc>>

let arc2 = Arc::clone(&arc);
thread::spawn(move || {
for x in 1..=10 {
if let Ok(mut v) = arc2.write() {
v.push(x);
}
}
});

thread::sleep(time::Duration::from_secs(3));
if let Ok(v) = arc.read() {
v.iter().for_each(|n| println!("{:?}", n));
};
}



<


<

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy b75f69e9899949f75391ec70afffa3d5