diff --git a/tower-layer/src/lib.rs b/tower-layer/src/lib.rs index d1694adf3..4823fcc16 100644 --- a/tower-layer/src/lib.rs +++ b/tower-layer/src/lib.rs @@ -19,6 +19,7 @@ mod identity; mod layer_fn; mod stack; +mod tuple; pub use self::{ identity::Identity, diff --git a/tower-layer/src/tuple.rs b/tower-layer/src/tuple.rs new file mode 100644 index 000000000..14b973abe --- /dev/null +++ b/tower-layer/src/tuple.rs @@ -0,0 +1,330 @@ +use crate::Layer; + +impl Layer for () { + type Service = S; + + fn layer(&self, service: S) -> Self::Service { + service + } +} + +impl Layer for (L1,) +where + L1: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1,) = self; + l1.layer(service) + } +} + +impl Layer for (L1, L2) +where + L1: Layer, + L2: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2) = self; + l1.layer(l2.layer(service)) + } +} + +impl Layer for (L1, L2, L3) +where + L1: Layer, + L2: Layer, + L3: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3) = self; + l1.layer((l2, l3).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4) = self; + l1.layer((l2, l3, l4).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5) = self; + l1.layer((l2, l3, l4, l5).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6) = self; + l1.layer((l2, l3, l4, l5, l6).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6, L7) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7) = self; + l1.layer((l2, l3, l4, l5, l6, l7).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6, L7, L8) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6, L7, L8, L9) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, + L14: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14).layer(service)) + } +} + +#[rustfmt::skip] +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, + L14: Layer, + L15: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15).layer(service)) + } +} + +#[rustfmt::skip] +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, + L14: Layer, + L15: Layer, + L16: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16).layer(service)) + } +}