9 Commits

Author SHA1 Message Date
dependabot[bot]
476e249be3 Bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-27 09:32:39 +01:00
a05739810d Enforce Item granularity 2025-11-27 09:30:03 +01:00
ed6676d345 Avoid broken docs in dependency 2025-11-27 09:30:03 +01:00
003f6a02d7 Prepare for release v0.3.2
This is a bugfix release and contains no new functionality.
2025-09-04 18:49:51 +02:00
d72827a74d Add missing fmt impls 2025-09-03 09:02:33 +02:00
df0f28b386 Relax sized bounds for std::sync wrappers 2025-09-03 09:02:33 +02:00
dependabot[bot]
8dec9db799 Bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-18 12:58:16 +02:00
28d67e871c Make elided lifetimes explicit 2025-08-18 12:51:08 +02:00
90843416e3 Missing section header 2025-05-13 16:09:39 +02:00
9 changed files with 104 additions and 36 deletions

View File

@@ -21,12 +21,12 @@ jobs:
- nightly - nightly
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@v1 - uses: dtolnay/rust-toolchain@master
with: with:
toolchain: ${{ matrix.rust }} toolchain: ${{ matrix.rust }}
components: rustfmt, clippy components: clippy
# Make sure we test with recent deps # Make sure we test with recent deps
- run: cargo update - run: cargo update
@@ -34,7 +34,6 @@ jobs:
if: "${{ matrix.rust != '1.74' }}" if: "${{ matrix.rust != '1.74' }}"
- run: cargo build --all-features --all-targets - run: cargo build --all-features --all-targets
- run: cargo test --all-features - run: cargo test --all-features
- run: cargo fmt --all -- --check
# Note: Rust 1.74 doesn't understand edition 2024 formatting so no point # Note: Rust 1.74 doesn't understand edition 2024 formatting so no point
if: "${{ matrix.rust != '1.74' }}" if: "${{ matrix.rust != '1.74' }}"
- run: cargo clippy --all-features --all-targets -- -D warnings - run: cargo clippy --all-features --all-targets -- -D warnings
@@ -43,28 +42,37 @@ jobs:
name: MSRV name: MSRV
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@v1 - uses: dtolnay/rust-toolchain@1.74
with: with:
toolchain: "1.70" toolchain: "1.70"
# Test everything except experimental features. # Test everything except experimental features.
- run: cargo test --features backtraces,lock_api,parking_lot - run: cargo test --features backtraces,lock_api,parking_lot
formatting:
name: Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
# Use nightly formatting options
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt --check
docs: docs:
name: Documentation build name: Documentation build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@v1 - uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
- name: Build documentation - name: Build documentation
env: env:
# Build the docs like docs.rs builds it # Build the docs like docs.rs builds it
RUSTDOCFLAGS: --cfg docsrs RUSTDOCFLAGS: --cfg docsrs
run: cargo doc --all-features run: cargo doc --all-features --no-deps

View File

@@ -6,6 +6,16 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
## [0.3.2]
### Fixed
- `std::sync` wrappers now no longer incorrectly require `T: Sized`
- Added missing `Display` and `Debug` implementations to `RwLock(Read|Write)Guard`.
## [0.3.1]
### Added ### Added
- On Rust 1.80 or newer, a wrapper for `std::sync::LazyLock` is now available. The MSRV has not been - On Rust 1.80 or newer, a wrapper for `std::sync::LazyLock` is now available. The MSRV has not been
@@ -124,7 +134,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Initial release. Initial release.
[Unreleased]: https://github.com/bertptrs/tracing-mutex/compare/v0.3.1...HEAD [Unreleased]: https://github.com/bertptrs/tracing-mutex/compare/v0.3.2...HEAD
[0.3.2]: https://github.com/bertptrs/tracing-mutex/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/bertptrs/tracing-mutex/compare/v0.3.0...v0.3.1 [0.3.1]: https://github.com/bertptrs/tracing-mutex/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/bertptrs/tracing-mutex/compare/v0.2.1...v0.3.0 [0.3.0]: https://github.com/bertptrs/tracing-mutex/compare/v0.2.1...v0.3.0
[0.2.1]: https://github.com/bertptrs/tracing-mutex/compare/v0.2.0...v0.2.1 [0.2.1]: https://github.com/bertptrs/tracing-mutex/compare/v0.2.0...v0.2.1

2
Cargo.lock generated
View File

@@ -597,7 +597,7 @@ dependencies = [
[[package]] [[package]]
name = "tracing-mutex" name = "tracing-mutex"
version = "0.3.1" version = "0.3.2"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"criterion", "criterion",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "tracing-mutex" name = "tracing-mutex"
version = "0.3.1" version = "0.3.2"
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
categories = ["concurrency", "development-tools::debugging"] categories = ["concurrency", "development-tools::debugging"]

View File

@@ -1 +1,2 @@
style_edition="2024" style_edition="2024"
imports_granularity="Item"

View File

@@ -163,7 +163,7 @@ impl MutexId {
/// # Panics /// # Panics
/// ///
/// This method panics if the new dependency would introduce a cycle. /// This method panics if the new dependency would introduce a cycle.
pub fn get_borrowed(&self) -> BorrowedMutex { pub fn get_borrowed(&self) -> BorrowedMutex<'_> {
self.mark_held(); self.mark_held();
BorrowedMutex { BorrowedMutex {
id: self, id: self,

View File

@@ -47,6 +47,8 @@ pub use parking_lot::WaitTimeoutResult;
pub mod tracing; pub mod tracing;
// Skip reformatting the combined imports as it duplicates the guards
#[rustfmt::skip]
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub use tracing::{ pub use tracing::{
FairMutex, FairMutexGuard, MappedFairMutexGuard, MappedMutexGuard, MappedReentrantMutexGuard, FairMutex, FairMutexGuard, MappedFairMutexGuard, MappedMutexGuard, MappedReentrantMutexGuard,
@@ -56,6 +58,7 @@ pub use tracing::{
const_reentrant_mutex, const_rwlock, const_reentrant_mutex, const_rwlock,
}; };
#[rustfmt::skip]
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
pub use parking_lot::{ pub use parking_lot::{
FairMutex, FairMutexGuard, MappedFairMutexGuard, MappedMutexGuard, MappedReentrantMutexGuard, FairMutex, FairMutexGuard, MappedFairMutexGuard, MappedMutexGuard, MappedReentrantMutexGuard,

View File

@@ -20,11 +20,14 @@
//! ``` //! ```
pub use std::sync as raw; pub use std::sync as raw;
// Skip reformatting the combined imports as it duplicates the guards
#[rustfmt::skip]
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
pub use std::sync::{ pub use std::sync::{
Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard, Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
}; };
#[rustfmt::skip]
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub use tracing::{ pub use tracing::{
Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard, Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,

View File

@@ -25,17 +25,16 @@ mod lazy_lock;
/// Refer to the [crate-level][`crate`] documentation for the differences between this struct and /// Refer to the [crate-level][`crate`] documentation for the differences between this struct and
/// the one it wraps. /// the one it wraps.
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Mutex<T> { pub struct Mutex<T: ?Sized> {
inner: sync::Mutex<T>,
id: LazyMutexId, id: LazyMutexId,
inner: sync::Mutex<T>,
} }
/// Wrapper for [`std::sync::MutexGuard`]. /// Wrapper for [`std::sync::MutexGuard`].
/// ///
/// Refer to the [crate-level][`crate`] documentation for the differences between this struct and /// Refer to the [crate-level][`crate`] documentation for the differences between this struct and
/// the one it wraps. /// the one it wraps.
#[derive(Debug)] pub struct MutexGuard<'a, T: ?Sized> {
pub struct MutexGuard<'a, T> {
inner: sync::MutexGuard<'a, T>, inner: sync::MutexGuard<'a, T>,
_mutex: BorrowedMutex<'a>, _mutex: BorrowedMutex<'a>,
} }
@@ -71,7 +70,9 @@ impl<T> Mutex<T> {
id: LazyMutexId::new(), id: LazyMutexId::new(),
} }
} }
}
impl<T: ?Sized> Mutex<T> {
/// Wrapper for [`std::sync::Mutex::lock`]. /// Wrapper for [`std::sync::Mutex::lock`].
/// ///
/// # Panics /// # Panics
@@ -79,7 +80,7 @@ impl<T> Mutex<T> {
/// This method participates in lock dependency tracking. If acquiring this lock introduces a /// This method participates in lock dependency tracking. If acquiring this lock introduces a
/// dependency cycle, this method will panic. /// dependency cycle, this method will panic.
#[track_caller] #[track_caller]
pub fn lock(&self) -> LockResult<MutexGuard<T>> { pub fn lock(&self) -> LockResult<MutexGuard<'_, T>> {
let mutex = self.id.get_borrowed(); let mutex = self.id.get_borrowed();
let result = self.inner.lock(); let result = self.inner.lock();
@@ -98,7 +99,7 @@ impl<T> Mutex<T> {
/// This method participates in lock dependency tracking. If acquiring this lock introduces a /// This method participates in lock dependency tracking. If acquiring this lock introduces a
/// dependency cycle, this method will panic. /// dependency cycle, this method will panic.
#[track_caller] #[track_caller]
pub fn try_lock(&self) -> TryLockResult<MutexGuard<T>> { pub fn try_lock(&self) -> TryLockResult<MutexGuard<'_, T>> {
let mutex = self.id.get_borrowed(); let mutex = self.id.get_borrowed();
let result = self.inner.try_lock(); let result = self.inner.try_lock();
@@ -123,12 +124,15 @@ impl<T> Mutex<T> {
} }
/// Unwrap the mutex and return its inner value. /// Unwrap the mutex and return its inner value.
pub fn into_inner(self) -> LockResult<T> { pub fn into_inner(self) -> LockResult<T>
where
T: Sized,
{
self.inner.into_inner() self.inner.into_inner()
} }
} }
impl<T> PrivateTraced for Mutex<T> { impl<T: ?Sized> PrivateTraced for Mutex<T> {
fn get_id(&self) -> &crate::MutexId { fn get_id(&self) -> &crate::MutexId {
&self.id &self.id
} }
@@ -140,21 +144,31 @@ impl<T> From<T> for Mutex<T> {
} }
} }
impl<T> Deref for MutexGuard<'_, T> { impl<T: ?Sized> Deref for MutexGuard<'_, T> {
type Target = T; type Target = T;
#[inline]
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.inner &self.inner
} }
} }
impl<T> DerefMut for MutexGuard<'_, T> { impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner &mut self.inner
} }
} }
impl<T: fmt::Display> fmt::Display for MutexGuard<'_, T> { impl<T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'_, T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
impl<T: fmt::Display + ?Sized> fmt::Display for MutexGuard<'_, T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f) self.inner.fmt(f)
} }
@@ -274,15 +288,14 @@ impl Condvar {
/// Wrapper for [`std::sync::RwLock`]. /// Wrapper for [`std::sync::RwLock`].
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct RwLock<T> { pub struct RwLock<T: ?Sized> {
inner: sync::RwLock<T>,
id: LazyMutexId, id: LazyMutexId,
inner: sync::RwLock<T>,
} }
/// Hybrid wrapper for both [`std::sync::RwLockReadGuard`] and [`std::sync::RwLockWriteGuard`]. /// Hybrid wrapper for both [`std::sync::RwLockReadGuard`] and [`std::sync::RwLockWriteGuard`].
/// ///
/// Please refer to [`RwLockReadGuard`] and [`RwLockWriteGuard`] for usable types. /// Please refer to [`RwLockReadGuard`] and [`RwLockWriteGuard`] for usable types.
#[derive(Debug)]
pub struct TracingRwLockGuard<'a, L> { pub struct TracingRwLockGuard<'a, L> {
inner: L, inner: L,
_mutex: BorrowedMutex<'a>, _mutex: BorrowedMutex<'a>,
@@ -300,7 +313,9 @@ impl<T> RwLock<T> {
id: LazyMutexId::new(), id: LazyMutexId::new(),
} }
} }
}
impl<T: ?Sized> RwLock<T> {
/// Wrapper for [`std::sync::RwLock::read`]. /// Wrapper for [`std::sync::RwLock::read`].
/// ///
/// # Panics /// # Panics
@@ -308,7 +323,7 @@ impl<T> RwLock<T> {
/// This method participates in lock dependency tracking. If acquiring this lock introduces a /// This method participates in lock dependency tracking. If acquiring this lock introduces a
/// dependency cycle, this method will panic. /// dependency cycle, this method will panic.
#[track_caller] #[track_caller]
pub fn read(&self) -> LockResult<RwLockReadGuard<T>> { pub fn read(&self) -> LockResult<RwLockReadGuard<'_, T>> {
let mutex = self.id.get_borrowed(); let mutex = self.id.get_borrowed();
let result = self.inner.read(); let result = self.inner.read();
@@ -325,7 +340,7 @@ impl<T> RwLock<T> {
/// This method participates in lock dependency tracking. If acquiring this lock introduces a /// This method participates in lock dependency tracking. If acquiring this lock introduces a
/// dependency cycle, this method will panic. /// dependency cycle, this method will panic.
#[track_caller] #[track_caller]
pub fn write(&self) -> LockResult<RwLockWriteGuard<T>> { pub fn write(&self) -> LockResult<RwLockWriteGuard<'_, T>> {
let mutex = self.id.get_borrowed(); let mutex = self.id.get_borrowed();
let result = self.inner.write(); let result = self.inner.write();
@@ -342,7 +357,7 @@ impl<T> RwLock<T> {
/// This method participates in lock dependency tracking. If acquiring this lock introduces a /// This method participates in lock dependency tracking. If acquiring this lock introduces a
/// dependency cycle, this method will panic. /// dependency cycle, this method will panic.
#[track_caller] #[track_caller]
pub fn try_read(&self) -> TryLockResult<RwLockReadGuard<T>> { pub fn try_read(&self) -> TryLockResult<RwLockReadGuard<'_, T>> {
let mutex = self.id.get_borrowed(); let mutex = self.id.get_borrowed();
let result = self.inner.try_read(); let result = self.inner.try_read();
@@ -359,7 +374,7 @@ impl<T> RwLock<T> {
/// This method participates in lock dependency tracking. If acquiring this lock introduces a /// This method participates in lock dependency tracking. If acquiring this lock introduces a
/// dependency cycle, this method will panic. /// dependency cycle, this method will panic.
#[track_caller] #[track_caller]
pub fn try_write(&self) -> TryLockResult<RwLockWriteGuard<T>> { pub fn try_write(&self) -> TryLockResult<RwLockWriteGuard<'_, T>> {
let mutex = self.id.get_borrowed(); let mutex = self.id.get_borrowed();
let result = self.inner.try_write(); let result = self.inner.try_write();
@@ -377,12 +392,15 @@ impl<T> RwLock<T> {
} }
/// Unwrap the mutex and return its inner value. /// Unwrap the mutex and return its inner value.
pub fn into_inner(self) -> LockResult<T> { pub fn into_inner(self) -> LockResult<T>
where
T: Sized,
{
self.inner.into_inner() self.inner.into_inner()
} }
} }
impl<T> PrivateTraced for RwLock<T> { impl<T: ?Sized> PrivateTraced for RwLock<T> {
fn get_id(&self) -> &crate::MutexId { fn get_id(&self) -> &crate::MutexId {
&self.id &self.id
} }
@@ -396,24 +414,48 @@ impl<T> From<T> for RwLock<T> {
impl<L, T> Deref for TracingRwLockGuard<'_, L> impl<L, T> Deref for TracingRwLockGuard<'_, L>
where where
T: ?Sized,
L: Deref<Target = T>, L: Deref<Target = T>,
{ {
type Target = T; type Target = T;
#[inline]
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
self.inner.deref() self.inner.deref()
} }
} }
impl<T, L> DerefMut for TracingRwLockGuard<'_, L> impl<L, T> DerefMut for TracingRwLockGuard<'_, L>
where where
T: ?Sized,
L: Deref<Target = T> + DerefMut, L: Deref<Target = T> + DerefMut,
{ {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
self.inner.deref_mut() self.inner.deref_mut()
} }
} }
impl<L> fmt::Debug for TracingRwLockGuard<'_, L>
where
L: fmt::Debug,
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
impl<L> fmt::Display for TracingRwLockGuard<'_, L>
where
L: fmt::Display,
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
/// Wrapper around [`std::sync::Once`]. /// Wrapper around [`std::sync::Once`].
/// ///
/// Refer to the [crate-level][`crate`] documentaiton for the differences between this struct /// Refer to the [crate-level][`crate`] documentaiton for the differences between this struct