summaryrefslogtreecommitdiff
path: root/src/lockable.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-09-13 15:12:08 -0400
committerMica White <botahamec@outlook.com>2026-09-13 15:12:08 -0400
commit16d6bd7ece4c4b9b72f6bd51c9b034270b745525 (patch)
tree4ff744fc41319ce73abe06416fabeaa7c17fbd46 /src/lockable.rs
parent9fd7b94cd7c20abe66cea875a0e83e76a7a00fbc (diff)
Support no_stdno-std
Diffstat (limited to 'src/lockable.rs')
-rwxr-xr-xsrc/lockable.rs37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/lockable.rs b/src/lockable.rs
index 705887f..e7f7f0a 100755
--- a/src/lockable.rs
+++ b/src/lockable.rs
@@ -1,4 +1,6 @@
-use std::mem::MaybeUninit;
+use core::mem::MaybeUninit;
+
+use alloc::{boxed::Box, vec::Vec};
/// A raw lock type that may be locked and unlocked
///
@@ -662,8 +664,12 @@ unsafe impl<T: OwnedLockable> OwnedLockable for Vec<T> {}
#[cfg(test)]
mod tests {
+ use alloc::vec;
+
use super::*;
- use crate::{LockCollection, Mutex, RwLock, ThreadKey};
+ #[cfg(feature = "std")]
+ use crate::{LockCollection, ThreadKey};
+ use crate::{Mutex, RwLock};
#[test]
fn mut_ref_get_ptrs() {
@@ -673,7 +679,7 @@ mod tests {
mutref.get_ptrs(&mut lock_ptrs);
assert_eq!(lock_ptrs.len(), 1);
- assert!(std::ptr::addr_eq(lock_ptrs[0], mutref));
+ assert!(core::ptr::addr_eq(lock_ptrs[0], mutref));
}
#[test]
@@ -692,7 +698,7 @@ mod tests {
locks.get_ptrs(&mut lock_ptrs);
assert_eq!(lock_ptrs.len(), 1);
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
}
#[test]
@@ -702,8 +708,8 @@ mod tests {
locks.get_ptrs(&mut lock_ptrs);
assert_eq!(lock_ptrs.len(), 2);
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[1], locks[1].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[1], locks[1].raw())) }
}
#[test]
@@ -722,7 +728,7 @@ mod tests {
locks.get_ptrs(&mut lock_ptrs);
assert_eq!(lock_ptrs.len(), 1);
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
}
#[test]
@@ -732,8 +738,8 @@ mod tests {
locks.get_ptrs(&mut lock_ptrs);
assert_eq!(lock_ptrs.len(), 2);
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[1], locks[1].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[1], locks[1].raw())) }
}
#[test]
@@ -757,6 +763,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn vec_guard_ref() {
let key = ThreadKey::get().unwrap();
let locks = vec![RwLock::new(1), RwLock::new(2)];
@@ -774,6 +781,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn vec_data_mut() {
let mut key = ThreadKey::get().unwrap();
let mutexes = vec![Mutex::new(1), Mutex::new(2)];
@@ -791,6 +799,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn vec_data_ref() {
let mut key = ThreadKey::get().unwrap();
let mutexes = vec![RwLock::new(1), RwLock::new(2)];
@@ -823,7 +832,7 @@ mod tests {
locks.get_ptrs(&mut lock_ptrs);
assert_eq!(lock_ptrs.len(), 1);
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
}
#[test]
@@ -833,8 +842,8 @@ mod tests {
locks.get_ptrs(&mut lock_ptrs);
assert_eq!(lock_ptrs.len(), 2);
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
- unsafe { assert!(std::ptr::addr_eq(lock_ptrs[1], locks[1].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[0], locks[0].raw())) }
+ unsafe { assert!(core::ptr::addr_eq(lock_ptrs[1], locks[1].raw())) }
}
#[test]
@@ -848,6 +857,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn box_guard_mut() {
let key = ThreadKey::get().unwrap();
let x = [Mutex::new(1), Mutex::new(2)];
@@ -865,6 +875,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn box_data_mut() {
let mut key = ThreadKey::get().unwrap();
let mutexes = vec![Mutex::new(1), Mutex::new(2)].into_boxed_slice();
@@ -882,6 +893,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn box_guard_ref() {
let key = ThreadKey::get().unwrap();
let locks = [RwLock::new(1), RwLock::new(2)];
@@ -899,6 +911,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn box_data_ref() {
let mut key = ThreadKey::get().unwrap();
let mutexes = vec![RwLock::new(1), RwLock::new(2)].into_boxed_slice();