summaryrefslogtreecommitdiff
path: root/src/collection/owned.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/collection/owned.rs
parent9fd7b94cd7c20abe66cea875a0e83e76a7a00fbc (diff)
Support no_stdno-std
Diffstat (limited to 'src/collection/owned.rs')
-rwxr-xr-xsrc/collection/owned.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/collection/owned.rs b/src/collection/owned.rs
index ab45e86..e53feb7 100755
--- a/src/collection/owned.rs
+++ b/src/collection/owned.rs
@@ -1,3 +1,5 @@
+use alloc::vec::Vec;
+
use crate::context::LockContext;
use crate::lockable::{
Lockable, LockableGetMut, LockableIntoInner, OwnedLockable, RawLock, Sharable,
@@ -676,10 +678,15 @@ impl<L: LockableIntoInner> OwnedLockCollection<L> {
#[cfg(test)]
mod tests {
+ use alloc::{string::String, vec};
+
use super::*;
- use crate::{LockCollection, Mutex, RwLock, ThreadKey};
+ use crate::{LockCollection, Mutex};
+ #[cfg(feature = "std")]
+ use crate::{RwLock, ThreadKey};
#[test]
+ #[cfg(feature = "std")]
fn get_mut_applies_changes() {
let key = ThreadKey::get().unwrap();
let mut collection = OwnedLockCollection::new([Mutex::new("foo"), Mutex::new("bar")]);
@@ -693,6 +700,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn into_inner_works() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::from([Mutex::new("foo")]);
@@ -727,6 +735,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn scoped_read_works() {
let mut key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new([RwLock::new(24), RwLock::new(42)]);
@@ -735,6 +744,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn scoped_lock_works() {
let mut key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new([RwLock::new(24), RwLock::new(42)]);
@@ -750,6 +760,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn scoped_try_lock_can_fail() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new([Mutex::new(1), Mutex::new(2)]);
@@ -767,6 +778,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn scoped_try_read_can_fail() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new([RwLock::new(1), RwLock::new(2)]);
@@ -784,6 +796,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn try_lock_works_on_unlocked() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new((Mutex::new(0), Mutex::new(1)));
@@ -793,6 +806,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn try_lock_fails_on_locked() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new((Mutex::new(0), Mutex::new(1)));
@@ -801,7 +815,7 @@ mod tests {
s.spawn(|| {
let key = ThreadKey::get().unwrap();
let guard = collection.lock(key);
- std::mem::forget(guard);
+ core::mem::forget(guard);
});
});
@@ -809,6 +823,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn try_read_succeeds_for_unlocked_collection() {
let key = ThreadKey::get().unwrap();
let mutexes = [RwLock::new(24), RwLock::new(42)];
@@ -819,6 +834,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn try_read_fails_on_locked() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new((RwLock::new(0), RwLock::new(1)));
@@ -827,7 +843,7 @@ mod tests {
s.spawn(|| {
let key = ThreadKey::get().unwrap();
let guard = collection.lock(key);
- std::mem::forget(guard);
+ core::mem::forget(guard);
});
});
@@ -835,6 +851,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn can_read_twice_on_different_threads() {
let key = ThreadKey::get().unwrap();
let mutexes = [RwLock::new(24), RwLock::new(42)];
@@ -846,7 +863,7 @@ mod tests {
let guard = collection.read(key);
assert_eq!(*guard[0], 24);
assert_eq!(*guard[1], 42);
- std::mem::forget(guard);
+ core::mem::forget(guard);
});
});
@@ -856,6 +873,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn unlock_collection_works() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new((Mutex::new("foo"), Mutex::new("bar")));
@@ -866,6 +884,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn read_unlock_collection_works() {
let key = ThreadKey::get().unwrap();
let collection = OwnedLockCollection::new((RwLock::new("foo"), RwLock::new("bar")));
@@ -897,6 +916,7 @@ mod tests {
}
#[test]
+ #[cfg(feature = "std")]
fn works_in_collection() {
let key = ThreadKey::get().unwrap();
let collection =