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/collection/guard.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/collection/guard.rs') diff --git a/src/collection/guard.rs b/src/collection/guard.rs index ab66ffe..a9bf66e 100755 --- a/src/collection/guard.rs +++ b/src/collection/guard.rs @@ -1,13 +1,13 @@ -use std::fmt::{Debug, Display}; -use std::hash::Hash; -use std::ops::{Deref, DerefMut}; +use core::fmt::{Debug, Display}; +use core::hash::Hash; +use core::ops::{Deref, DerefMut}; use super::LockGuard; #[mutants::skip] // hashing involves RNG and is hard to test #[cfg(not(tarpaulin_include))] impl Hash for LockGuard { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { self.guard.hash(state) } } @@ -20,13 +20,13 @@ impl Hash for LockGuard { #[mutants::skip] #[cfg(not(tarpaulin_include))] impl Debug for LockGuard { - 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 LockGuard { - 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) } } @@ -59,10 +59,13 @@ impl AsMut for LockGuard { #[cfg(test)] mod tests { + #[cfg(feature = "std")] use crate::collection::OwnedLockCollection; + #[cfg(feature = "std")] use crate::{LockCollection, Mutex, RwLock, ThreadKey}; #[test] + #[cfg(feature = "std")] fn guard_display_works() { let key = ThreadKey::get().unwrap(); let lock = OwnedLockCollection::new(RwLock::new("Hello, world!")); @@ -71,6 +74,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn deref_mut_works() { let key = ThreadKey::get().unwrap(); let locks = (Mutex::new(1), Mutex::new(2)); @@ -88,6 +92,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn as_ref_works() { let key = ThreadKey::get().unwrap(); let locks = (Mutex::new(1), Mutex::new(2)); @@ -105,6 +110,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn as_mut_works() { let key = ThreadKey::get().unwrap(); let locks = (Mutex::new(1), Mutex::new(2)); -- cgit v1.3.1