1 //! Internal macros 2 3 macro_rules! opaque_future { 4 ($(#[$m:meta])* pub type $name:ident = $actual:ty;) => { 5 opaque_future! { 6 $(#[$m])* 7 pub type $name<> = $actual; 8 } 9 }; 10 11 ($(#[$m:meta])* pub type $name:ident<$($param:ident),*> = $actual:ty;) => { 12 pin_project_lite::pin_project! { 13 $(#[$m])* 14 pub struct $name<$($param),*> { 15 #[pin] future: $actual, 16 } 17 } 18 19 impl<$($param),*> $name<$($param),*> { 20 pub(crate) fn new(future: $actual) -> Self { 21 Self { future } 22 } 23 } 24 25 impl<$($param),*> std::fmt::Debug for $name<$($param),*> { 26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 27 f.debug_struct(stringify!($name)).finish_non_exhaustive() 28 } 29 } 30 31 impl<$($param),*> std::future::Future for $name<$($param),*> 32 where 33 $actual: std::future::Future, 34 { 35 type Output = <$actual as std::future::Future>::Output; 36 37 #[inline] 38 fn poll( 39 self: std::pin::Pin<&mut Self>, 40 cx: &mut std::task::Context<'_>, 41 ) -> std::task::Poll<Self::Output> { 42 self.project().future.poll(cx) 43 } 44 } 45 }; 46 } 47 48 #[rustfmt::skip] 49 macro_rules! all_the_tuples { 50 ($name:ident) => { 51 $name!([], T1); 52 $name!([T1], T2); 53 $name!([T1, T2], T3); 54 $name!([T1, T2, T3], T4); 55 $name!([T1, T2, T3, T4], T5); 56 $name!([T1, T2, T3, T4, T5], T6); 57 $name!([T1, T2, T3, T4, T5, T6], T7); 58 $name!([T1, T2, T3, T4, T5, T6, T7], T8); 59 $name!([T1, T2, T3, T4, T5, T6, T7, T8], T9); 60 $name!([T1, T2, T3, T4, T5, T6, T7, T8, T9], T10); 61 $name!([T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T11); 62 $name!([T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11], T12); 63 $name!([T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12], T13); 64 $name!([T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13], T14); 65 $name!([T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14], T15); 66 $name!([T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15], T16); 67 }; 68 } 69