diff --git a/Cargo.toml b/Cargo.toml index bc705a8..5e3da1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,8 @@ arbitrary = [ ] std = [ ] -async-std = [ "dep:async-std", "async-std/alloc", "async-std/default" ] +async-std = [ "dep:async-std" ] +async-std-task = [ "async-std", "async-std/alloc", "async-std/default" ] tokio1 = [ "dep:tokio1" ] tokio1-sync = [ "tokio1", "tokio1/sync" ] tokio1-task = [ "tokio1", "tokio1/rt" ] diff --git a/src/impl_async_std.rs b/src/impl_async_std.rs index 7a3c0e8..3774983 100644 --- a/src/impl_async_std.rs +++ b/src/impl_async_std.rs @@ -1,22 +1,25 @@ -use async_std::task::JoinHandle; +#[cfg(feature = "async-std-task")] +mod impl_task { + use async_std::task::JoinHandle; -use crate::{DropGuard, DropGuarded}; + use crate::{DropGuard, DropGuarded}; -impl DropGuarded for JoinHandle { - #[inline] - fn cancel(self) { - let _ = JoinHandle::::cancel(self); - } -} - -impl core::future::Future for DropGuard> { - type Output = T; - - fn poll( - mut self: core::pin::Pin<&mut Self>, - cx: &mut core::task::Context<'_>, - ) -> core::task::Poll { - let handle = (*self).inner.as_mut().expect("can only be None in drop"); - core::pin::Pin::new(handle).poll(cx) + impl DropGuarded for JoinHandle { + #[inline] + fn cancel(self) { + let _ = JoinHandle::::cancel(self); + } + } + + impl core::future::Future for DropGuard> { + type Output = T; + + fn poll( + mut self: core::pin::Pin<&mut Self>, + cx: &mut core::task::Context<'_>, + ) -> core::task::Poll { + let handle = (*self).inner.as_mut().expect("can only be None in drop"); + core::pin::Pin::new(handle).poll(cx) + } } } diff --git a/src/impl_tokio1.rs b/src/impl_tokio1.rs index 6a72365..d3c2d76 100644 --- a/src/impl_tokio1.rs +++ b/src/impl_tokio1.rs @@ -1,5 +1,3 @@ -use crate::DropGuarded; - #[cfg(feature = "tokio1-task")] mod impl_task { use crate::{DropGuard, DropGuarded}; @@ -28,17 +26,20 @@ mod impl_task { } #[cfg(feature = "tokio1-sync")] -impl DropGuarded for tokio1::sync::oneshot::Sender<()> { - #[inline] - fn cancel(self) { - let _ = self.send(()); - } -} +mod impl_sync { + use crate::DropGuarded; -#[cfg(all(feature = "tokio1-sync", feature = "std"))] -impl DropGuarded for std::sync::Arc { - #[inline] - fn cancel(self) { - self.close(); + impl DropGuarded for tokio1::sync::oneshot::Sender<()> { + #[inline] + fn cancel(self) { + let _ = self.send(()); + } + } + #[cfg(feature = "std")] + impl DropGuarded for std::sync::Arc { + #[inline] + fn cancel(self) { + self.close(); + } } }