summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-02-07 10:45:11 -0500
committerMica White <botahamec@outlook.com>2026-02-07 10:45:11 -0500
commit2096d0c6819ce0e8f6c6e77e36ebc495924dad63 (patch)
treefcee36a7aa3e3d77a8d57d1585d6ee095b4ff676 /src
parent9d928375ffc365d9ae4f4bc9be4a3c08fae47387 (diff)
Rename data to child
Diffstat (limited to 'src')
-rwxr-xr-xsrc/collection.rs9
-rwxr-xr-xsrc/collection/boxed.rs10
-rwxr-xr-xsrc/collection/owned.rs48
-rwxr-xr-xsrc/collection/ref.rs30
-rwxr-xr-xsrc/collection/retry.rs48
5 files changed, 72 insertions, 73 deletions
diff --git a/src/collection.rs b/src/collection.rs
index 9c04fbb..c97bbd2 100755
--- a/src/collection.rs
+++ b/src/collection.rs
@@ -29,8 +29,7 @@ pub(crate) mod utils;
// collection exist
#[derive(Debug)]
pub struct OwnedLockCollection<L> {
- // TODO: rename to child
- data: L,
+ child: L,
}
/// Locks a reference to a collection of locks, by sorting them by memory
@@ -59,7 +58,7 @@ pub struct OwnedLockCollection<L> {
// This type caches the sorting order of the locks and the fact that it doesn't
// contain any duplicates.
pub struct RefLockCollection<'a, L> {
- data: &'a L,
+ child: &'a L,
locks: Vec<&'a dyn RawLock>,
}
@@ -85,7 +84,7 @@ pub struct RefLockCollection<'a, L> {
// This type caches the sorting order of the locks and the fact that it doesn't
// contain any duplicates.
pub struct BoxedLockCollection<L> {
- data: *const UnsafeCell<L>,
+ child: *const UnsafeCell<L>,
locks: Vec<&'static dyn RawLock>,
}
@@ -112,7 +111,7 @@ pub struct BoxedLockCollection<L> {
// This type caches the fact that there are no duplicates
#[derive(Debug)]
pub struct RetryingLockCollection<L> {
- data: L,
+ child: L,
}
/// A RAII guard for a generic [`Lockable`] type. When this structure is
diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs
index 3708c8b..3600d8e 100755
--- a/src/collection/boxed.rs
+++ b/src/collection/boxed.rs
@@ -153,7 +153,7 @@ impl<L> Drop for BoxedLockCollection<L> {
// safety: this collection will never be locked again
self.locks.clear();
// safety: this was allocated using a box, and is now unique
- let boxed: Box<UnsafeCell<L>> = Box::from_raw(self.data.cast_mut());
+ let boxed: Box<UnsafeCell<L>> = Box::from_raw(self.child.cast_mut());
drop(boxed)
}
@@ -171,7 +171,7 @@ impl<T: ?Sized, L: AsRef<T>> AsRef<T> for BoxedLockCollection<L> {
impl<L: Debug> Debug for BoxedLockCollection<L> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!(BoxedLockCollection))
- .field("data", &self.data)
+ .field("data", &self.child)
// there's not much reason to show the sorted locks
.finish_non_exhaustive()
}
@@ -209,7 +209,7 @@ impl<L> BoxedLockCollection<L> {
// safety: this collection will never be used again
std::ptr::drop_in_place(&mut self.locks);
// safety: this was allocated using a box, and is now unique
- let boxed: Box<UnsafeCell<L>> = Box::from_raw(self.data.cast_mut());
+ let boxed: Box<UnsafeCell<L>> = Box::from_raw(self.child.cast_mut());
// to prevent a double free
std::mem::forget(self);
@@ -238,7 +238,7 @@ impl<L> BoxedLockCollection<L> {
#[must_use]
pub fn child(&self) -> &L {
unsafe {
- self.data
+ self.child
.as_ref()
.unwrap_unchecked()
.get()
@@ -329,7 +329,7 @@ impl<L: Lockable> BoxedLockCollection<L> {
// safety: we're just changing the lifetimes
let locks: Vec<&'static dyn RawLock> = std::mem::transmute(locks);
let data = &raw const *data;
- Self { data, locks }
+ Self { child: data, locks }
}
/// Creates a new collection of locks.
diff --git a/src/collection/owned.rs b/src/collection/owned.rs
index d6889d1..02d434c 100755
--- a/src/collection/owned.rs
+++ b/src/collection/owned.rs
@@ -10,39 +10,39 @@ unsafe impl<L: Lockable> RawLock for OwnedLockCollection<L> {
#[mutants::skip] // this should never run
#[cfg(not(tarpaulin_include))]
fn poison(&self) {
- let locks = utils::get_locks_unsorted(&self.data);
+ let locks = utils::get_locks_unsorted(&self.child);
for lock in locks {
lock.poison();
}
}
unsafe fn raw_write(&self) {
- utils::ordered_write(&utils::get_locks_unsorted(&self.data))
+ utils::ordered_write(&utils::get_locks_unsorted(&self.child))
}
unsafe fn raw_try_write(&self) -> bool {
- let locks = utils::get_locks_unsorted(&self.data);
+ let locks = utils::get_locks_unsorted(&self.child);
utils::ordered_try_write(&locks)
}
unsafe fn raw_unlock_write(&self) {
- let locks = utils::get_locks_unsorted(&self.data);
+ let locks = utils::get_locks_unsorted(&self.child);
for lock in locks {
lock.raw_unlock_write();
}
}
unsafe fn raw_read(&self) {
- utils::ordered_read(&utils::get_locks_unsorted(&self.data))
+ utils::ordered_read(&utils::get_locks_unsorted(&self.child))
}
unsafe fn raw_try_read(&self) -> bool {
- let locks = utils::get_locks_unsorted(&self.data);
+ let locks = utils::get_locks_unsorted(&self.child);
utils::ordered_try_read(&locks)
}
unsafe fn raw_unlock_read(&self) {
- let locks = utils::get_locks_unsorted(&self.data);
+ let locks = utils::get_locks_unsorted(&self.child);
for lock in locks {
lock.raw_unlock_read();
}
@@ -70,11 +70,11 @@ unsafe impl<L: Lockable> Lockable for OwnedLockCollection<L> {
}
unsafe fn guard(&self) -> Self::Guard<'_> {
- self.data.guard()
+ self.child.guard()
}
unsafe fn data_mut(&self) -> Self::DataMut<'_> {
- self.data.data_mut()
+ self.child.data_mut()
}
}
@@ -85,7 +85,7 @@ impl<L: LockableGetMut> LockableGetMut for OwnedLockCollection<L> {
Self: 'a;
fn get_mut(&mut self) -> Self::Inner<'_> {
- self.data.get_mut()
+ self.child.get_mut()
}
}
@@ -93,7 +93,7 @@ impl<L: LockableIntoInner> LockableIntoInner for OwnedLockCollection<L> {
type Inner = L::Inner;
fn into_inner(self) -> Self::Inner {
- self.data.into_inner()
+ self.child.into_inner()
}
}
@@ -109,11 +109,11 @@ unsafe impl<L: Sharable> Sharable for OwnedLockCollection<L> {
Self: 'a;
unsafe fn read_guard(&self) -> Self::ReadGuard<'_> {
- self.data.read_guard()
+ self.child.read_guard()
}
unsafe fn data_ref(&self) -> Self::DataRef<'_> {
- self.data.data_ref()
+ self.child.data_ref()
}
}
@@ -127,7 +127,7 @@ where
type IntoIter = <L as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
- self.data.into_iter()
+ self.child.into_iter()
}
}
@@ -142,7 +142,7 @@ impl<L: OwnedLockable, I: FromIterator<L> + OwnedLockable> FromIterator<L>
impl<E: OwnedLockable + Extend<L>, L: OwnedLockable> Extend<L> for OwnedLockCollection<E> {
fn extend<T: IntoIterator<Item = L>>(&mut self, iter: T) {
- self.data.extend(iter)
+ self.child.extend(iter)
}
}
@@ -152,7 +152,7 @@ impl<E: OwnedLockable + Extend<L>, L: OwnedLockable> Extend<L> for OwnedLockColl
impl<T: ?Sized, L: AsMut<T>> AsMut<T> for OwnedLockCollection<L> {
fn as_mut(&mut self) -> &mut T {
- self.data.as_mut()
+ self.child.as_mut()
}
}
@@ -186,7 +186,7 @@ impl<L: OwnedLockable> OwnedLockCollection<L> {
/// ```
#[must_use]
pub const fn new(data: L) -> Self {
- Self { data }
+ Self { child: data }
}
pub fn scoped_lock<'a, R>(
@@ -232,7 +232,7 @@ impl<L: OwnedLockable> OwnedLockCollection<L> {
self.raw_write();
// safety: we've locked all of this already
- self.data.guard()
+ self.child.guard()
};
LockGuard { guard, key }
@@ -276,7 +276,7 @@ impl<L: OwnedLockable> OwnedLockCollection<L> {
}
// safety: we've acquired the locks
- self.data.guard()
+ self.child.guard()
};
Ok(LockGuard { guard, key })
@@ -351,7 +351,7 @@ impl<L: Sharable> OwnedLockCollection<L> {
LockGuard {
// safety: we've already acquired the lock
- guard: self.data.read_guard(),
+ guard: self.child.read_guard(),
key,
}
}
@@ -396,7 +396,7 @@ impl<L: Sharable> OwnedLockCollection<L> {
}
// safety: we've acquired the locks
- self.data.read_guard()
+ self.child.read_guard()
};
Ok(LockGuard { guard, key })
@@ -444,7 +444,7 @@ impl<L> OwnedLockCollection<L> {
/// ```
#[must_use]
pub fn into_child(self) -> L {
- self.data
+ self.child
}
/// Gets a mutable reference to the underlying collection.
@@ -465,7 +465,7 @@ impl<L> OwnedLockCollection<L> {
/// ```
#[must_use]
pub fn child_mut(&mut self) -> &mut L {
- &mut self.data
+ &mut self.child
}
}
@@ -729,7 +729,7 @@ mod tests {
collection.extend([Mutex::new(2)]);
- assert_eq!(collection.data.len(), 3);
+ assert_eq!(collection.child.len(), 3);
}
#[test]
diff --git a/src/collection/ref.rs b/src/collection/ref.rs
index d180ab0..4ba06bd 100755
--- a/src/collection/ref.rs
+++ b/src/collection/ref.rs
@@ -17,7 +17,7 @@ where
type IntoIter = <&'a L as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
- self.data.into_iter()
+ self.child.into_iter()
}
}
@@ -77,11 +77,11 @@ unsafe impl<L: Lockable> Lockable for RefLockCollection<'_, L> {
}
unsafe fn guard(&self) -> Self::Guard<'_> {
- self.data.guard()
+ self.child.guard()
}
unsafe fn data_mut(&self) -> Self::DataMut<'_> {
- self.data.data_mut()
+ self.child.data_mut()
}
}
@@ -97,17 +97,17 @@ unsafe impl<L: Sharable> Sharable for RefLockCollection<'_, L> {
Self: 'a;
unsafe fn read_guard(&self) -> Self::ReadGuard<'_> {
- self.data.read_guard()
+ self.child.read_guard()
}
unsafe fn data_ref(&self) -> Self::DataRef<'_> {
- self.data.data_ref()
+ self.child.data_ref()
}
}
impl<T: ?Sized, L: AsRef<T>> AsRef<T> for RefLockCollection<'_, L> {
fn as_ref(&self) -> &T {
- self.data.as_ref()
+ self.child.as_ref()
}
}
@@ -116,7 +116,7 @@ impl<T: ?Sized, L: AsRef<T>> AsRef<T> for RefLockCollection<'_, L> {
impl<L: Debug> Debug for RefLockCollection<'_, L> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!(RefLockCollection))
- .field("data", self.data)
+ .field("data", self.child)
// there's not much reason to show the sorting order
.finish_non_exhaustive()
}
@@ -152,7 +152,7 @@ impl<'a, L: OwnedLockable> RefLockCollection<'a, L> {
pub fn new(data: &'a L) -> Self {
RefLockCollection {
locks: get_locks(data),
- data,
+ child: data,
}
}
}
@@ -179,7 +179,7 @@ impl<L> RefLockCollection<'_, L> {
/// ```
#[must_use]
pub const fn child(&self) -> &L {
- self.data
+ self.child
}
}
@@ -207,7 +207,7 @@ impl<'a, L: Lockable> RefLockCollection<'a, L> {
#[must_use]
pub unsafe fn new_unchecked(data: &'a L) -> Self {
Self {
- data,
+ child: data,
locks: get_locks(data),
}
}
@@ -237,7 +237,7 @@ impl<'a, L: Lockable> RefLockCollection<'a, L> {
return None;
}
- Some(Self { data, locks })
+ Some(Self { child: data, locks })
}
pub fn scoped_lock<'s, R>(
@@ -283,7 +283,7 @@ impl<'a, L: Lockable> RefLockCollection<'a, L> {
self.raw_write();
// safety: we've locked all of this already
- self.data.guard()
+ self.child.guard()
};
LockGuard { guard, key }
@@ -327,7 +327,7 @@ impl<'a, L: Lockable> RefLockCollection<'a, L> {
}
// safety: we've acquired the locks
- self.data.guard()
+ self.child.guard()
};
Ok(LockGuard { guard, key })
@@ -403,7 +403,7 @@ impl<L: Sharable> RefLockCollection<'_, L> {
LockGuard {
// safety: we've already acquired the lock
- guard: self.data.read_guard(),
+ guard: self.child.read_guard(),
key,
}
}
@@ -448,7 +448,7 @@ impl<L: Sharable> RefLockCollection<'_, L> {
}
// safety: we've acquired the locks
- self.data.read_guard()
+ self.child.read_guard()
};
Ok(LockGuard { guard, key })
diff --git a/src/collection/retry.rs b/src/collection/retry.rs
index e127c20..64e8ca8 100755
--- a/src/collection/retry.rs
+++ b/src/collection/retry.rs
@@ -35,14 +35,14 @@ unsafe impl<L: Lockable> RawLock for RetryingLockCollection<L> {
#[mutants::skip] // this should never run
#[cfg(not(tarpaulin_include))]
fn poison(&self) {
- let locks = get_locks_unsorted(&self.data);
+ let locks = get_locks_unsorted(&self.child);
for lock in locks {
lock.poison();
}
}
unsafe fn raw_write(&self) {
- let locks = get_locks_unsorted(&self.data);
+ let locks = get_locks_unsorted(&self.child);
if locks.is_empty() {
// this probably prevents a panic later
@@ -104,7 +104,7 @@ unsafe impl<L: Lockable> RawLock for RetryingLockCollection<L> {
}
unsafe fn raw_try_write(&self) -> bool {
- let locks = get_locks_unsorted(&self.data);
+ let locks = get_locks_unsorted(&self.child);
if locks.is_empty() {
// this is an interesting case, but it doesn't give us access to
@@ -134,7 +134,7 @@ unsafe impl<L: Lockable> RawLock for RetryingLockCollection<L> {
}
unsafe fn raw_unlock_write(&self) {
- let locks = get_locks_unsorted(&self.data);
+ let locks = get_locks_unsorted(&self.child);
for lock in locks {
lock.raw_unlock_write();
@@ -142,7 +142,7 @@ unsafe impl<L: Lockable> RawLock for RetryingLockCollection<L> {
}
unsafe fn raw_read(&self) {
- let locks = get_locks_unsorted(&self.data);
+ let locks = get_locks_unsorted(&self.child);
if locks.is_empty() {
// this probably prevents a panic later
@@ -195,7 +195,7 @@ unsafe impl<L: Lockable> RawLock for RetryingLockCollection<L> {
}
unsafe fn raw_try_read(&self) -> bool {
- let locks = get_locks_unsorted(&self.data);
+ let locks = get_locks_unsorted(&self.child);
if locks.is_empty() {
// this is an interesting case, but it doesn't give us access to
@@ -224,7 +224,7 @@ unsafe impl<L: Lockable> RawLock for RetryingLockCollection<L> {
}
unsafe fn raw_unlock_read(&self) {
- let locks = get_locks_unsorted(&self.data);
+ let locks = get_locks_unsorted(&self.child);
for lock in locks {
lock.raw_unlock_read();
@@ -246,15 +246,15 @@ unsafe impl<L: Lockable> Lockable for RetryingLockCollection<L> {
fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) {
// this collection, just like the sorting collection, must return all of its
// locks in order to check for duplication
- self.data.get_ptrs(ptrs)
+ self.child.get_ptrs(ptrs)
}
unsafe fn guard(&self) -> Self::Guard<'_> {
- self.data.guard()
+ self.child.guard()
}
unsafe fn data_mut(&self) -> Self::DataMut<'_> {
- self.data.data_mut()
+ self.child.data_mut()
}
}
@@ -270,11 +270,11 @@ unsafe impl<L: Sharable> Sharable for RetryingLockCollection<L> {
Self: 'a;
unsafe fn read_guard(&self) -> Self::ReadGuard<'_> {
- self.data.read_guard()
+ self.child.read_guard()
}
unsafe fn data_ref(&self) -> Self::DataRef<'_> {
- self.data.data_ref()
+ self.child.data_ref()
}
}
@@ -287,7 +287,7 @@ impl<L: LockableGetMut> LockableGetMut for RetryingLockCollection<L> {
Self: 'a;
fn get_mut(&mut self) -> Self::Inner<'_> {
- self.data.get_mut()
+ self.child.get_mut()
}
}
@@ -295,7 +295,7 @@ impl<L: LockableIntoInner> LockableIntoInner for RetryingLockCollection<L> {
type Inner = L::Inner;
fn into_inner(self) -> Self::Inner {
- self.data.into_inner()
+ self.child.into_inner()
}
}
@@ -307,7 +307,7 @@ where
type IntoIter = <L as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
- self.data.into_iter()
+ self.child.into_iter()
}
}
@@ -319,7 +319,7 @@ where
type IntoIter = <&'a L as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
- self.data.into_iter()
+ self.child.into_iter()
}
}
@@ -331,7 +331,7 @@ where
type IntoIter = <&'a mut L as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
- self.data.into_iter()
+ self.child.into_iter()
}
}
@@ -346,19 +346,19 @@ impl<L: OwnedLockable, I: FromIterator<L> + OwnedLockable> FromIterator<L>
impl<E: OwnedLockable + Extend<L>, L: OwnedLockable> Extend<L> for RetryingLockCollection<E> {
fn extend<T: IntoIterator<Item = L>>(&mut self, iter: T) {
- self.data.extend(iter)
+ self.child.extend(iter)
}
}
impl<T: ?Sized, L: AsRef<T>> AsRef<T> for RetryingLockCollection<L> {
fn as_ref(&self) -> &T {
- self.data.as_ref()
+ self.child.as_ref()
}
}
impl<T: ?Sized, L: AsMut<T>> AsMut<T> for RetryingLockCollection<L> {
fn as_mut(&mut self) -> &mut T {
- self.data.as_mut()
+ self.child.as_mut()
}
}
@@ -442,7 +442,7 @@ impl<L> RetryingLockCollection<L> {
/// ```
#[must_use]
pub const unsafe fn new_unchecked(data: L) -> Self {
- Self { data }
+ Self { child: data }
}
/// Gets an immutable reference to the underlying collection.
@@ -463,7 +463,7 @@ impl<L> RetryingLockCollection<L> {
/// ```
#[must_use]
pub const fn child(&self) -> &L {
- &self.data
+ &self.child
}
/// Gets a mutable reference to the underlying collection.
@@ -484,7 +484,7 @@ impl<L> RetryingLockCollection<L> {
/// ```
#[must_use]
pub fn child_mut(&mut self) -> &mut L {
- &mut self.data
+ &mut self.child
}
/// Gets the underlying collection, consuming this collection.
@@ -505,7 +505,7 @@ impl<L> RetryingLockCollection<L> {
/// ```
#[must_use]
pub fn into_child(self) -> L {
- self.data
+ self.child
}
}