Skip to content

Commit 6fc00c0

Browse files
committed
feat: Move Future impl to forwarding macro
Signed-off-by: John Nunley <[email protected]>
1 parent e0fefc2 commit 6fc00c0

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/lib.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ pub trait Listener<T>: Future<Output = T> + __sealed::Sealed {
833833
fn same_event(&self, other: &Self) -> bool;
834834
}
835835

836+
/// Implement the `Listener` trait using the underlying `InnerListener`.
836837
macro_rules! forward_impl_to_listener {
837838
($gen:ident => $ty:ty) => {
838839
impl<$gen> crate::Listener<$gen> for $ty {
@@ -869,6 +870,15 @@ macro_rules! forward_impl_to_listener {
869870
core::ptr::eq::<Inner<$gen>>(&*self.listener().event, &*other.listener().event)
870871
}
871872
}
873+
874+
impl<$gen> Future for $ty {
875+
type Output = $gen;
876+
877+
#[inline]
878+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<$gen> {
879+
self.listener_mut().poll_internal(cx)
880+
}
881+
}
872882
};
873883
}
874884

@@ -922,14 +932,6 @@ impl<T> EventListener<T> {
922932

923933
forward_impl_to_listener! { T => EventListener<T> }
924934

925-
impl<T> Future for EventListener<T> {
926-
type Output = T;
927-
928-
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
929-
self.listener.as_mut().poll_internal(cx)
930-
}
931-
}
932-
933935
/// Create a stack-based event listener for an [`Event`].
934936
#[macro_export]
935937
macro_rules! listener {
@@ -1376,13 +1378,4 @@ pub mod __private {
13761378
}
13771379

13781380
forward_impl_to_listener! { T => StackListener<'_, '_, T> }
1379-
1380-
impl<T> Future for StackListener<'_, '_, T> {
1381-
type Output = T;
1382-
1383-
#[inline]
1384-
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
1385-
self.listener_mut().poll_internal(cx)
1386-
}
1387-
}
13881381
}

0 commit comments

Comments
 (0)