summaryrefslogtreecommitdiff
path: root/src/poisonable/poisonable.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-08-26 20:46:31 -0400
committerMica White <botahamec@outlook.com>2026-08-26 20:46:31 -0400
commit55b3a2425b242fbc5c6e471f220eeb8b949e8751 (patch)
tree5ceb7910b60cc7331024b7ce1d49ec259e0302a8 /src/poisonable/poisonable.rs
parent6f6e030ea7edb9d155ebf21b5d42936c20801b50 (diff)
Add tests
Diffstat (limited to 'src/poisonable/poisonable.rs')
-rwxr-xr-xsrc/poisonable/poisonable.rs22
1 files changed, 21 insertions, 1 deletions
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<L: LockableGetMut + RawLock> Poisonable<L> {
}
}
+impl<L: OwnedLockable> Poisonable<OwnedLockCollection<L>> {
+ /// 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<LockContext<'_, L>> {
+ if self.is_poisoned() {
+ Ok(self.inner.context())
+ } else {
+ Err(PoisonError::new(self.inner.context()))
+ }
+ }
+}
+
impl<L: UnwindSafe> RefUnwindSafe for Poisonable<L> {}
impl<L: UnwindSafe> UnwindSafe for Poisonable<L> {}