diff --git a/src/lib.rs b/src/lib.rs index a543459..f2269bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -833,6 +833,7 @@ pub trait Listener: Future + __sealed::Sealed { fn same_event(&self, other: &Self) -> bool; } +/// Implement the `Listener` trait using the underlying `InnerListener`. macro_rules! forward_impl_to_listener { ($gen:ident => $ty:ty) => { impl<$gen> crate::Listener<$gen> for $ty { @@ -869,6 +870,15 @@ macro_rules! forward_impl_to_listener { core::ptr::eq::>(&*self.listener().event, &*other.listener().event) } } + + impl<$gen> Future for $ty { + type Output = $gen; + + #[inline] + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<$gen> { + self.listener_mut().poll_internal(cx) + } + } }; } @@ -922,14 +932,6 @@ impl EventListener { forward_impl_to_listener! { T => EventListener } -impl Future for EventListener { - type Output = T; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.listener.as_mut().poll_internal(cx) - } -} - /// Create a stack-based event listener for an [`Event`]. #[macro_export] macro_rules! listener { @@ -1376,13 +1378,4 @@ pub mod __private { } forward_impl_to_listener! { T => StackListener<'_, '_, T> } - - impl Future for StackListener<'_, '_, T> { - type Output = T; - - #[inline] - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.listener_mut().poll_internal(cx) - } - } }