diff options
| author | Mica White <botahamec@gmail.com> | 2024-12-25 17:58:38 -0500 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-12-25 22:44:03 -0500 |
| commit | 311842d28d1fbb6da945f0d98f1655f77a58abf9 (patch) | |
| tree | 4da3c8ab6fb3732c1ebb11306dab3799decd6b2c /src/collection/ref.rs | |
| parent | 37ab873d21ca1fcd43db8d6a26d5bac4f5285f71 (diff) | |
as_mut re-organization
Diffstat (limited to 'src/collection/ref.rs')
| -rw-r--r-- | src/collection/ref.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/collection/ref.rs b/src/collection/ref.rs index a9fc915..4fa5485 100644 --- a/src/collection/ref.rs +++ b/src/collection/ref.rs @@ -23,13 +23,8 @@ fn contains_duplicates(l: &[&dyn RawLock]) -> bool { } l.windows(2) - .any(|window| std::ptr::eq(window[0], window[1])) -} - -impl<L> AsRef<L> for RefLockCollection<'_, L> { - fn as_ref(&self) -> &L { - self.data - } + // NOTE: addr_eq is necessary because eq would also compare the v-table pointers + .any(|window| std::ptr::addr_eq(window[0], window[1])) } impl<'a, L> IntoIterator for &'a RefLockCollection<'a, L> @@ -106,6 +101,12 @@ unsafe impl<L: Sharable> Sharable for RefLockCollection<'_, L> { } } +impl<T, L: AsRef<T>> AsRef<T> for RefLockCollection<'_, L> { + fn as_ref(&self) -> &T { + self.data.as_ref() + } +} + impl<L: Debug> Debug for RefLockCollection<'_, L> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct(stringify!(RefLockCollection)) @@ -149,6 +150,13 @@ impl<'a, L: OwnedLockable> RefLockCollection<'a, L> { } } +impl<L> RefLockCollection<'_, L> { + #[must_use] + pub const fn child(&self) -> &L { + self.data + } +} + impl<'a, L: Lockable> RefLockCollection<'a, L> { /// Creates a new collections of locks. /// @@ -262,11 +270,11 @@ impl<'a, L: Lockable> RefLockCollection<'a, L> { /// let lock = RefLockCollection::new(&data); /// /// match lock.try_lock(key) { - /// Some(mut guard) => { + /// Ok(mut guard) => { /// *guard.0 += 1; /// *guard.1 = "1"; /// }, - /// None => unreachable!(), + /// Err(_) => unreachable!(), /// }; /// /// ``` |
