std-type
TryLockError: busy versus poisoned
Match the error category and select a policy. Busy can mean the caller should do other work; poisoning calls for an invariant review or failure propagation. Expected stdout (not executed): busy Common mistake: Handling all errors by spinning until a lock is available.
Formal Syntax & Structure
rust syntaxrust
TryLockError::WouldBlock | TryLockError::Poisoned(error)Working Example
Example Snippetrust
fn main() { use std::sync::{Mutex, TryLockError}; let m = Mutex::new(1); let _guard = m.lock().unwrap(); let label = match m.try_lock() { Ok(_) => "acquired", Err(TryLockError::WouldBlock) => "busy", Err(TryLockError::Poisoned(_)) => "poisoned" }; println!("{label}");}