fn_ptr/
tuple.rs

1use crate::arity::{self, A0, A1, A2, A3, A4, A5, A6};
2#[cfg(feature = "max-arity-12")]
3use crate::arity::{A7, A8, A9, A10, A11, A12};
4
5cfg_tt::cfg_tt! {
6/// A trait implemented for all tuple types up to arity 6 (or 12 with feature `max-arity-12`).
7pub trait Tuple
8    #[cfg(nightly_build)]
9    (: core::marker::Tuple) {
10    /// Type-level representation of this tuple’s arity.
11    ///
12    /// For example:
13    /// - `()` -> `A0`
14    /// - `(T,)` -> `A1`
15    /// - `(T, U)` -> `A2`
16    type Arity: arity::Arity;
17
18    #[doc(hidden)]
19    // This is required for WithArgs
20    type BaseFn: crate::FnPtr<Args = Self>;
21}
22}
23
24/// Internal helper macro to generate `Tuple` implementations.
25macro_rules! impl_tuple {
26    // arity 0
27    (0, $arity:ty) => {
28        impl Tuple for () {
29            type Arity = $arity;
30            type BaseFn = fn();
31        }
32    };
33
34    // arity N >= 1
35    ($n:tt, $arity:ty, ( $($T:ident),+ )) => {
36        impl< $($T),+ > Tuple for ( $($T,)+ ) {
37            type Arity = $arity;
38            type BaseFn = fn($($T,)+);
39        }
40    };
41}
42
43impl_tuple!(0, A0);
44impl_tuple!(1, A1, (T1));
45impl_tuple!(2, A2, (T1, T2));
46impl_tuple!(3, A3, (T1, T2, T3));
47impl_tuple!(4, A4, (T1, T2, T3, T4));
48impl_tuple!(5, A5, (T1, T2, T3, T4, T5));
49impl_tuple!(6, A6, (T1, T2, T3, T4, T5, T6));
50#[cfg(feature = "max-arity-12")]
51impl_tuple!(7, A7, (T1, T2, T3, T4, T5, T6, T7));
52#[cfg(feature = "max-arity-12")]
53impl_tuple!(8, A8, (T1, T2, T3, T4, T5, T6, T7, T8));
54#[cfg(feature = "max-arity-12")]
55impl_tuple!(9, A9, (T1, T2, T3, T4, T5, T6, T7, T8, T9));
56#[cfg(feature = "max-arity-12")]
57impl_tuple!(10, A10, (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10));
58#[cfg(feature = "max-arity-12")]
59impl_tuple!(11, A11, (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11));
60#[cfg(feature = "max-arity-12")]
61impl_tuple!(12, A12, (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12));