diff options
| author | Botahamec <botahamec@outlook.com> | 2024-09-25 20:55:52 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2024-09-25 20:55:52 -0400 |
| commit | 05b0b24acaf304d89101e9f5bea8989c495c0f44 (patch) | |
| tree | 62fc78d719638dee590e37827941994453f69752 /src/poisonable/poisonable.rs | |
| parent | cc57eea563e9c12122dd47c8b6133dab8660c1b4 (diff) | |
Better error implementation
Diffstat (limited to 'src/poisonable/poisonable.rs')
| -rw-r--r-- | src/poisonable/poisonable.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/poisonable/poisonable.rs b/src/poisonable/poisonable.rs index 6c78346..f774e2d 100644 --- a/src/poisonable/poisonable.rs +++ b/src/poisonable/poisonable.rs @@ -26,7 +26,7 @@ unsafe impl<L: Lockable + RawLock> Lockable for Poisonable<L> { if self.is_poisoned() { Ok(ref_guard) } else { - Err(PoisonError { guard: ref_guard }) + Err(PoisonError::new(ref_guard)) } } @@ -39,7 +39,7 @@ unsafe impl<L: Lockable + RawLock> Lockable for Poisonable<L> { if self.is_poisoned() { Ok(ref_guard) } else { - Err(PoisonError { guard: ref_guard }) + Err(PoisonError::new(ref_guard)) } } } @@ -71,11 +71,11 @@ impl<L: Lockable + RawLock> Poisonable<L> { _phantom: PhantomData, }; - if self.is_poisoned() { - Ok(guard) - } else { - Err(PoisonError { guard }) + if !self.is_poisoned() { + return Err(PoisonError::new(guard)); } + + Ok(guard) } pub fn lock<'flag, 'key, Key: Keyable + 'key>( @@ -118,7 +118,7 @@ impl<L: Lockable + RawLock> Poisonable<L> { pub fn into_inner(self) -> PoisonResult<L> { if self.is_poisoned() { - Err(PoisonError { guard: self.inner }) + Err(PoisonError::new(self.inner)) } else { Ok(self.inner) } @@ -126,9 +126,7 @@ impl<L: Lockable + RawLock> Poisonable<L> { pub fn get_mut(&mut self) -> PoisonResult<&mut L> { if self.is_poisoned() { - Err(PoisonError { - guard: &mut self.inner, - }) + Err(PoisonError::new(&mut self.inner)) } else { Ok(&mut self.inner) } |
