From 16d6bd7ece4c4b9b72f6bd51c9b034270b745525 Mon Sep 17 00:00:00 2001 From: Mica White Date: Sun, 13 Sep 2026 15:12:08 -0400 Subject: Support no_std --- src/poisonable/error.rs | 2 +- src/poisonable/flag.rs | 2 +- src/poisonable/guard.rs | 26 ++++++++++++++------------ src/poisonable/poisonable.rs | 4 +++- 4 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/poisonable') diff --git a/src/poisonable/error.rs b/src/poisonable/error.rs index eed454b..b7b9206 100755 --- a/src/poisonable/error.rs +++ b/src/poisonable/error.rs @@ -1,5 +1,5 @@ +use core::error::Error; use core::fmt; -use std::error::Error; use super::{PoisonError, PoisonGuard, TryLockPoisonableError}; diff --git a/src/poisonable/flag.rs b/src/poisonable/flag.rs index 9186bbc..9877245 100755 --- a/src/poisonable/flag.rs +++ b/src/poisonable/flag.rs @@ -1,5 +1,5 @@ #[cfg(panic = "unwind")] -use std::sync::atomic::{AtomicBool, Ordering::Relaxed}; +use core::sync::atomic::{AtomicBool, Ordering::Relaxed}; use super::PoisonFlag; diff --git a/src/poisonable/guard.rs b/src/poisonable/guard.rs index 32b4ee8..c4d9250 100755 --- a/src/poisonable/guard.rs +++ b/src/poisonable/guard.rs @@ -1,16 +1,18 @@ -use std::fmt::{Debug, Display}; -use std::hash::Hash; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; +use core::fmt::{Debug, Display}; +use core::hash::Hash; +use core::marker::PhantomData; +use core::ops::{Deref, DerefMut}; use super::{PoisonFlag, PoisonGuard, PoisonRef}; impl<'a, Guard> PoisonRef<'a, Guard> { // This is used so that we don't keep accidentally adding the flag reference + #[allow(clippy::allow_attributes)] + #[allow(unused_variables)] pub(super) const fn new(flag: &'a PoisonFlag, guard: Guard) -> Self { Self { guard, - #[cfg(panic = "unwind")] + #[cfg(all(feature = "std", panic = "unwind"))] flag, _phantom: PhantomData, } @@ -19,7 +21,7 @@ impl<'a, Guard> PoisonRef<'a, Guard> { impl Drop for PoisonRef<'_, Guard> { fn drop(&mut self) { - #[cfg(panic = "unwind")] + #[cfg(all(feature = "std", panic = "unwind"))] if std::thread::panicking() { self.flag.poison(); } @@ -29,7 +31,7 @@ impl Drop for PoisonRef<'_, Guard> { #[mutants::skip] // hashing involves RNG and is hard to test #[cfg(not(tarpaulin_include))] impl Hash for PoisonRef<'_, Guard> { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { self.guard.hash(state) } } @@ -37,13 +39,13 @@ impl Hash for PoisonRef<'_, Guard> { #[mutants::skip] #[cfg(not(tarpaulin_include))] impl Debug for PoisonRef<'_, Guard> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { Debug::fmt(&**self, f) } } impl Display for PoisonRef<'_, Guard> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { Display::fmt(&**self, f) } } @@ -77,7 +79,7 @@ impl AsMut for PoisonRef<'_, Guard> { #[mutants::skip] // hashing involves RNG and is hard to test #[cfg(not(tarpaulin_include))] impl Hash for PoisonGuard<'_, Guard> { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { self.guard.hash(state) } } @@ -85,13 +87,13 @@ impl Hash for PoisonGuard<'_, Guard> { #[mutants::skip] #[cfg(not(tarpaulin_include))] impl Debug for PoisonGuard<'_, Guard> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { Debug::fmt(&self.guard, f) } } impl Display for PoisonGuard<'_, Guard> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { Display::fmt(&self.guard, f) } } diff --git a/src/poisonable/poisonable.rs b/src/poisonable/poisonable.rs index 0134ff1..ccca07e 100755 --- a/src/poisonable/poisonable.rs +++ b/src/poisonable/poisonable.rs @@ -1,4 +1,6 @@ -use std::panic::{RefUnwindSafe, UnwindSafe}; +use core::panic::{RefUnwindSafe, UnwindSafe}; + +use alloc::vec::Vec; use crate::collection::OwnedLockCollection; use crate::handle_unwind::handle_unwind; -- cgit v1.3.1