mirror of https://github.com/smol-rs/async-lock
Add stable_deref_trait feature
This commit is contained in:
parent
5a89518c9d
commit
1f83512b93
|
@ -17,6 +17,7 @@ exclude = ["/.*"]
|
|||
[dependencies]
|
||||
futures-lite = "1.11.0"
|
||||
event-listener = "2.5.1"
|
||||
stable_deref_trait = { version = "1.2.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
async-channel = "1.5.0"
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -6,6 +6,16 @@
|
|||
//! * [`Mutex`] - a mutual exclusion lock.
|
||||
//! * [`RwLock`] - a reader-writer lock, allowing any number of readers or a single writer.
|
||||
//! * [`Semaphore`] - limits the number of concurrent operations.
|
||||
//!
|
||||
//! # Features
|
||||
//!
|
||||
//! - `stable_deref_trait` - Uses the [`stable_deref_trait`] crate to implement the [`StableDeref`] trait
|
||||
//! for the guards of the synchronization primitives. This allows these types to be used in crates like
|
||||
//! [`owning_ref`].
|
||||
//!
|
||||
//! [`stable_deref_trait`]: https://crates.io/crates/stable_deref_trait
|
||||
//! [`StableDeref`]: https://docs.rs/stable_deref_trait/latest/stable_deref_trait/trait.StableDeref.html
|
||||
//! [`owning_ref`]: https://crates.io/crates/owning_ref
|
||||
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
|
||||
|
|
|
@ -412,6 +412,9 @@ impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stable_deref_trait")]
|
||||
unsafe impl<T: ?Sized> stable_deref_trait::StableDeref for MutexGuard<'_, T> {}
|
||||
|
||||
/// An owned guard that releases the mutex when dropped.
|
||||
pub struct MutexGuardArc<T: ?Sized>(Arc<Mutex<T>>);
|
||||
|
||||
|
@ -472,6 +475,9 @@ impl<T: ?Sized> DerefMut for MutexGuardArc<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stable_deref_trait")]
|
||||
unsafe impl<T: ?Sized> stable_deref_trait::StableDeref for MutexGuardArc<T> {}
|
||||
|
||||
/// Calls a function when dropped.
|
||||
struct CallOnDrop<F: Fn()>(F);
|
||||
|
||||
|
|
|
@ -484,6 +484,9 @@ impl<T: ?Sized> Deref for RwLockReadGuard<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stable_deref_trait")]
|
||||
unsafe impl<T: ?Sized> stable_deref_trait::StableDeref for RwLockReadGuard<'_, T> {}
|
||||
|
||||
/// A guard that releases the upgradable read lock when dropped.
|
||||
pub struct RwLockUpgradableReadGuard<'a, T: ?Sized> {
|
||||
reader: RwLockReadGuard<'a, T>,
|
||||
|
@ -632,6 +635,9 @@ impl<T: ?Sized> Deref for RwLockUpgradableReadGuard<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stable_deref_trait")]
|
||||
unsafe impl<T: ?Sized> stable_deref_trait::StableDeref for RwLockUpgradableReadGuard<'_, T> {}
|
||||
|
||||
struct RwLockWriteGuardInner<'a, T: ?Sized>(&'a RwLock<T>);
|
||||
|
||||
impl<T: ?Sized> Drop for RwLockWriteGuardInner<'_, T> {
|
||||
|
@ -758,3 +764,6 @@ impl<T: ?Sized> DerefMut for RwLockWriteGuard<'_, T> {
|
|||
unsafe { &mut *self.writer.0.value.get() }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stable_deref_trait")]
|
||||
unsafe impl<T: ?Sized> stable_deref_trait::StableDeref for RwLockWriteGuard<'_, T> {}
|
||||
|
|
Loading…
Reference in New Issue