From 55b3a2425b242fbc5c6e471f220eeb8b949e8751 Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 26 Aug 2026 20:46:31 -0400 Subject: Add tests --- src/poisonable/poisonable.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/poisonable/poisonable.rs') diff --git a/src/poisonable/poisonable.rs b/src/poisonable/poisonable.rs index dd12cea..0134ff1 100755 --- a/src/poisonable/poisonable.rs +++ b/src/poisonable/poisonable.rs @@ -1,10 +1,11 @@ use std::panic::{RefUnwindSafe, UnwindSafe}; +use crate::collection::OwnedLockCollection; use crate::handle_unwind::handle_unwind; use crate::lockable::{ Lockable, LockableGetMut, LockableIntoInner, OwnedLockable, RawLock, Sharable, }; -use crate::{Keyable, ThreadKey}; +use crate::{Keyable, LockContext, ThreadKey}; use super::{ PoisonError, PoisonFlag, PoisonGuard, PoisonRef, PoisonResult, Poisonable, @@ -853,5 +854,24 @@ impl Poisonable { } } +impl Poisonable> { + /// Creates a context that can be used to iterate over the items in order. + /// + /// For more information, see [`OwnedLockCollection::context`]. + /// + /// # Errors + /// + /// If another user of this lock panicked while holding the lock, then + /// this call will return an error instead. A `Poisonable` is poisoned + /// whenever a thread panics while holding a lock. + pub fn context(&self) -> PoisonResult> { + if self.is_poisoned() { + Ok(self.inner.context()) + } else { + Err(PoisonError::new(self.inner.context())) + } + } +} + impl RefUnwindSafe for Poisonable {} impl UnwindSafe for Poisonable {} -- cgit v1.3.1