| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/; |
| 4 | |
| 5 | use encloserust-analyzer cargo enclose 1.2.1 crate/::encloserust-analyzer cargo enclose 1.2.1 enclose!; |
| 6 | |
| 7 | fn mainrust-analyzer cargo enclose 1.2.1 main().() { |
| 8 | let mutex_data = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]new().(0)); |
| 9 | let thread = threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/spawn().(encloserust-analyzer cargo enclose 1.2.1 enclose!!((mutex_data => d, @1024 => my_var) move || { |
| 10 | // (mutex_data => d) -> |
| 11 | // let d = mutex_data.clone(); |
| 12 | // let my_var = 1024; |
| 13 | |
| 14 | let mut lock = match d.lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().() { |
| 15 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(a) => a, |
| 16 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e.into_innerrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/impl#[`PoisonError<T>`]into_inner().(), |
| 17 | }; |
| 18 | *rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][DerefMut]deref_mut().lock += my_var; |
| 19 | })); |
| 20 | |
| 21 | thread.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/join_handle/impl#[`JoinHandle<T>`]join().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 22 | { |
| 23 | let lock = match mutex_data.lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().() { |
| 24 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(a) => a, |
| 25 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e.into_innerrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/impl#[`PoisonError<T>`]into_inner().(), |
| 26 | }; |
| 27 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][Deref]deref().lock, 1024); |
| 28 | } |
| 29 | } |