2022-05-26 10:49:13 -04:00
|
|
|
pub struct DropGuard<T: DropGuarded> {
|
|
|
|
inner: Option<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: DropGuarded> DropGuard<T> {
|
|
|
|
#[inline]
|
|
|
|
pub fn unguard(mut self) -> T {
|
|
|
|
self.inner.take().expect("only None in drop")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait DropGuarded {
|
|
|
|
fn cancel(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: DropGuarded> DropGuard<T> {
|
|
|
|
#[inline]
|
2022-06-15 16:41:55 -04:00
|
|
|
pub const fn new(guarded: T) -> Self {
|
2022-05-26 10:49:13 -04:00
|
|
|
Self {
|
|
|
|
inner: Some(guarded),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: DropGuarded> Drop for DropGuard<T> {
|
|
|
|
#[inline]
|
|
|
|
fn drop(&mut self) {
|
|
|
|
if let Some(inner) = self.inner.take() {
|
|
|
|
inner.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 16:41:55 -04:00
|
|
|
#[cfg(feature = "arbitrary")]
|
|
|
|
mod impl_arbitrary;
|
|
|
|
#[cfg(feature = "arbitrary")]
|
|
|
|
pub use impl_arbitrary::ArbitraryDropGuard;
|
2022-05-26 10:49:13 -04:00
|
|
|
|
2022-06-15 16:41:55 -04:00
|
|
|
#[cfg(feature = "async-std")]
|
|
|
|
mod impl_async_std;
|
|
|
|
|
|
|
|
#[cfg(feature = "tokio1")]
|
|
|
|
mod impl_tokio1;
|
|
|
|
|
|
|
|
#[cfg(feature = "triggered")]
|
|
|
|
mod impl_triggered;
|