handy_async/matcher/
match_tuple.rs

1use futures::{self, Async, Poll, Future};
2
3use error::AsyncError;
4use matcher::{AsyncMatch, Matcher};
5use matcher::futures::MatchChain;
6
7impl<M: Matcher> AsyncMatch<M> for () {
8    type Future = futures::Finished<(M, ()), AsyncError<M, M::Error>>;
9    fn async_match(self, matcher: M) -> Self::Future {
10        futures::finished((matcher, self))
11    }
12}
13
14impl<M: Matcher, P0, P1> AsyncMatch<M> for (P0, P1)
15where
16    P0: AsyncMatch<M>,
17    P1: AsyncMatch<M>,
18{
19    type Future = MatchChain<M, P0, P1>;
20    fn async_match(self, matcher: M) -> Self::Future {
21        let (p0, p1) = self;
22        p0.chain(p1).async_match(matcher)
23    }
24}
25
26/// Future to do pattern matching of
27/// [Tuple3](../../pattern/combinators/type.Tuple3.html) pattern.
28#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
29pub struct MatchTuple3<M, A, B, C>
30where
31    M: Matcher,
32    A: AsyncMatch<M>,
33    B: AsyncMatch<M>,
34    C: AsyncMatch<M>,
35{
36    phase: Phase<(A::Future, B, C), (B::Future, C, A::Value), (C::Future, A::Value, B::Value)>,
37}
38#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
39impl<M, A, B, C> Future for MatchTuple3<M, A, B, C>
40where
41    M: Matcher,
42    A: AsyncMatch<M>,
43    B: AsyncMatch<M>,
44    C: AsyncMatch<M>,
45{
46    type Item = (M, (A::Value, B::Value, C::Value));
47    type Error = AsyncError<M, M::Error>;
48    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
49        match self.phase.take() {
50            Phase::A((mut future, b, c)) => {
51                if let Async::Ready((m, v)) = future.poll()? {
52                    self.phase = Phase::B((b.async_match(m), c, v));
53                    self.poll()
54                } else {
55                    self.phase = Phase::A((future, b, c));
56                    Ok(Async::NotReady)
57                }
58            }
59            Phase::B((mut future, c, a)) => {
60                if let Async::Ready((m, v)) = future.poll()? {
61                    self.phase = Phase::C((c.async_match(m), a, v));
62                    self.poll()
63                } else {
64                    self.phase = Phase::B((future, c, a));
65                    Ok(Async::NotReady)
66                }
67            }
68            Phase::C((mut future, a, b)) => {
69                if let Async::Ready((m, v)) = future.poll()? {
70                    Ok(Async::Ready((m, (a, b, v))))
71                } else {
72                    self.phase = Phase::C((future, a, b));
73                    Ok(Async::NotReady)
74                }
75            }
76            _ => panic!("Cannot poll MatchTuple3 twice"),
77        }
78    }
79}
80impl<M, A, B, C> AsyncMatch<M> for (A, B, C)
81where
82    M: Matcher,
83    A: AsyncMatch<M>,
84    B: AsyncMatch<M>,
85    C: AsyncMatch<M>,
86{
87    type Future = MatchTuple3<M, A, B, C>;
88    fn async_match(self, matcher: M) -> Self::Future {
89        let (a, b, c) = self;
90        MatchTuple3 { phase: Phase::A((a.async_match(matcher), b, c)) }
91    }
92}
93
94/// Future to do pattern matching of
95/// [Tuple4](../../pattern/combinators/type.Tuple4.html) pattern.
96#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
97pub struct MatchTuple4<M, A, B, C, D>
98where
99    M: Matcher,
100    A: AsyncMatch<M>,
101    B: AsyncMatch<M>,
102    C: AsyncMatch<M>,
103    D: AsyncMatch<M>,
104{
105    p: Phase<
106        (A::Future, B, C, D),
107        (B::Future, C, D, A::Value),
108        (C::Future, D, A::Value, B::Value),
109        (D::Future, A::Value, B::Value, C::Value),
110    >,
111}
112#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
113impl<M, A, B, C, D> Future for MatchTuple4<M, A, B, C, D>
114where
115    M: Matcher,
116    A: AsyncMatch<M>,
117    B: AsyncMatch<M>,
118    C: AsyncMatch<M>,
119    D: AsyncMatch<M>,
120{
121    type Item = (M, (A::Value, B::Value, C::Value, D::Value));
122    type Error = AsyncError<M, M::Error>;
123    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
124        match self.p.take() {
125            Phase::A((mut future, b, c, d)) => {
126                if let Async::Ready((m, v)) = future.poll()? {
127                    self.p = Phase::B((b.async_match(m), c, d, v));
128                    self.poll()
129                } else {
130                    self.p = Phase::A((future, b, c, d));
131                    Ok(Async::NotReady)
132                }
133            }
134            Phase::B((mut future, c, d, a)) => {
135                if let Async::Ready((m, v)) = future.poll()? {
136                    self.p = Phase::C((c.async_match(m), d, a, v));
137                    self.poll()
138                } else {
139                    self.p = Phase::B((future, c, d, a));
140                    Ok(Async::NotReady)
141                }
142            }
143            Phase::C((mut future, d, a, b)) => {
144                if let Async::Ready((m, v)) = future.poll()? {
145                    self.p = Phase::D((d.async_match(m), a, b, v));
146                    self.poll()
147                } else {
148                    self.p = Phase::C((future, d, a, b));
149                    Ok(Async::NotReady)
150                }
151            }
152            Phase::D((mut future, a, b, c)) => {
153                if let Async::Ready((m, v)) = future.poll()? {
154                    Ok(Async::Ready((m, (a, b, c, v))))
155                } else {
156                    self.p = Phase::D((future, a, b, c));
157                    Ok(Async::NotReady)
158                }
159            }
160            _ => panic!("Cannot poll MatchTuple4 twice"),
161        }
162    }
163}
164impl<M, A, B, C, D> AsyncMatch<M> for (A, B, C, D)
165where
166    M: Matcher,
167    A: AsyncMatch<M>,
168    B: AsyncMatch<M>,
169    C: AsyncMatch<M>,
170    D: AsyncMatch<M>,
171{
172    type Future = MatchTuple4<M, A, B, C, D>;
173    fn async_match(self, matcher: M) -> Self::Future {
174        let (a, b, c, d) = self;
175        MatchTuple4 { p: Phase::A((a.async_match(matcher), b, c, d)) }
176    }
177}
178
179/// Future to do pattern matching of
180/// [Tuple5](../../pattern/combinators/type.Tuple5.html) pattern.
181#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
182pub struct MatchTuple5<M, A, B, C, D, E>
183where
184    M: Matcher,
185    A: AsyncMatch<M>,
186    B: AsyncMatch<M>,
187    C: AsyncMatch<M>,
188    D: AsyncMatch<M>,
189    E: AsyncMatch<M>,
190{
191    p: Phase<
192        (A::Future, B, C, D, E),
193        (B::Future, C, D, E, A::Value),
194        (C::Future, D, E, A::Value, B::Value),
195        (D::Future, E, A::Value, B::Value, C::Value),
196        (E::Future, A::Value, B::Value, C::Value, D::Value),
197    >,
198}
199#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
200impl<M, A, B, C, D, E> Future for MatchTuple5<M, A, B, C, D, E>
201where
202    M: Matcher,
203    A: AsyncMatch<M>,
204    B: AsyncMatch<M>,
205    C: AsyncMatch<M>,
206    D: AsyncMatch<M>,
207    E: AsyncMatch<M>,
208{
209    type Item = (M, (A::Value, B::Value, C::Value, D::Value, E::Value));
210    type Error = AsyncError<M, M::Error>;
211    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
212        match self.p.take() {
213            Phase::A((mut future, b, c, d, e)) => {
214                if let Async::Ready((m, v)) = future.poll()? {
215                    self.p = Phase::B((b.async_match(m), c, d, e, v));
216                    self.poll()
217                } else {
218                    self.p = Phase::A((future, b, c, d, e));
219                    Ok(Async::NotReady)
220                }
221            }
222            Phase::B((mut future, c, d, e, a)) => {
223                if let Async::Ready((m, v)) = future.poll()? {
224                    self.p = Phase::C((c.async_match(m), d, e, a, v));
225                    self.poll()
226                } else {
227                    self.p = Phase::B((future, c, d, e, a));
228                    Ok(Async::NotReady)
229                }
230            }
231            Phase::C((mut future, d, e, a, b)) => {
232                if let Async::Ready((m, v)) = future.poll()? {
233                    self.p = Phase::D((d.async_match(m), e, a, b, v));
234                    self.poll()
235                } else {
236                    self.p = Phase::C((future, d, e, a, b));
237                    Ok(Async::NotReady)
238                }
239            }
240            Phase::D((mut future, e, a, b, c)) => {
241                if let Async::Ready((m, v)) = future.poll()? {
242                    self.p = Phase::E((e.async_match(m), a, b, c, v));
243                    self.poll()
244                } else {
245                    self.p = Phase::D((future, e, a, b, c));
246                    Ok(Async::NotReady)
247                }
248            }
249            Phase::E((mut future, a, b, c, d)) => {
250                if let Async::Ready((m, v)) = future.poll()? {
251                    Ok(Async::Ready((m, (a, b, c, d, v))))
252                } else {
253                    self.p = Phase::E((future, a, b, c, d));
254                    Ok(Async::NotReady)
255                }
256            }
257            _ => panic!("Cannot poll MatchTuple5 twice"),
258        }
259    }
260}
261impl<M, A, B, C, D, E> AsyncMatch<M> for (A, B, C, D, E)
262where
263    M: Matcher,
264    A: AsyncMatch<M>,
265    B: AsyncMatch<M>,
266    C: AsyncMatch<M>,
267    D: AsyncMatch<M>,
268    E: AsyncMatch<M>,
269{
270    type Future = MatchTuple5<M, A, B, C, D, E>;
271    fn async_match(self, matcher: M) -> Self::Future {
272        let (a, b, c, d, e) = self;
273        MatchTuple5 { p: Phase::A((a.async_match(matcher), b, c, d, e)) }
274    }
275}
276
277/// Future to do pattern matching of
278/// [Tuple6](../../pattern/combinators/type.Tuple6.html) pattern.
279#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
280pub struct MatchTuple6<M, A, B, C, D, E, F>
281where
282    M: Matcher,
283    A: AsyncMatch<M>,
284    B: AsyncMatch<M>,
285    C: AsyncMatch<M>,
286    D: AsyncMatch<M>,
287    E: AsyncMatch<M>,
288    F: AsyncMatch<M>,
289{
290    p: Phase<
291        (A::Future, B, C, D, E, F),
292        (B::Future, C, D, E, F, A::Value),
293        (C::Future, D, E, F, A::Value, B::Value),
294        (D::Future, E, F, A::Value, B::Value, C::Value),
295        (E::Future, F, A::Value, B::Value, C::Value, D::Value),
296        (F::Future, A::Value, B::Value, C::Value, D::Value, E::Value),
297    >,
298}
299#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
300impl<M, A, B, C, D, E, F> Future for MatchTuple6<M, A, B, C, D, E, F>
301where
302    M: Matcher,
303    A: AsyncMatch<M>,
304    B: AsyncMatch<M>,
305    C: AsyncMatch<M>,
306    D: AsyncMatch<M>,
307    E: AsyncMatch<M>,
308    F: AsyncMatch<M>,
309{
310    type Item = (M, (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value));
311    type Error = AsyncError<M, M::Error>;
312    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
313        match self.p.take() {
314            Phase::A((mut future, b, c, d, e, f)) => {
315                if let Async::Ready((m, v)) = future.poll()? {
316                    self.p = Phase::B((b.async_match(m), c, d, e, f, v));
317                    self.poll()
318                } else {
319                    self.p = Phase::A((future, b, c, d, e, f));
320                    Ok(Async::NotReady)
321                }
322            }
323            Phase::B((mut future, c, d, e, f, a)) => {
324                if let Async::Ready((m, v)) = future.poll()? {
325                    self.p = Phase::C((c.async_match(m), d, e, f, a, v));
326                    self.poll()
327                } else {
328                    self.p = Phase::B((future, c, d, e, f, a));
329                    Ok(Async::NotReady)
330                }
331            }
332            Phase::C((mut future, d, e, f, a, b)) => {
333                if let Async::Ready((m, v)) = future.poll()? {
334                    self.p = Phase::D((d.async_match(m), e, f, a, b, v));
335                    self.poll()
336                } else {
337                    self.p = Phase::C((future, d, e, f, a, b));
338                    Ok(Async::NotReady)
339                }
340            }
341            Phase::D((mut future, e, f, a, b, c)) => {
342                if let Async::Ready((m, v)) = future.poll()? {
343                    self.p = Phase::E((e.async_match(m), f, a, b, c, v));
344                    self.poll()
345                } else {
346                    self.p = Phase::D((future, e, f, a, b, c));
347                    Ok(Async::NotReady)
348                }
349            }
350            Phase::E((mut future, f, a, b, c, d)) => {
351                if let Async::Ready((m, v)) = future.poll()? {
352                    self.p = Phase::F((f.async_match(m), a, b, c, d, v));
353                    self.poll()
354                } else {
355                    self.p = Phase::E((future, f, a, b, c, d));
356                    Ok(Async::NotReady)
357                }
358            }
359            Phase::F((mut future, a, b, c, d, e)) => {
360                if let Async::Ready((m, v)) = future.poll()? {
361                    Ok(Async::Ready((m, (a, b, c, d, e, v))))
362                } else {
363                    self.p = Phase::F((future, a, b, c, d, e));
364                    Ok(Async::NotReady)
365                }
366            }
367            _ => panic!("Cannot poll MatchTuple6 twice"),
368        }
369    }
370}
371impl<M, A, B, C, D, E, F> AsyncMatch<M> for (A, B, C, D, E, F)
372where
373    M: Matcher,
374    A: AsyncMatch<M>,
375    B: AsyncMatch<M>,
376    C: AsyncMatch<M>,
377    D: AsyncMatch<M>,
378    E: AsyncMatch<M>,
379    F: AsyncMatch<M>,
380{
381    type Future = MatchTuple6<M, A, B, C, D, E, F>;
382    fn async_match(self, matcher: M) -> Self::Future {
383        let (a, b, c, d, e, f) = self;
384        MatchTuple6 { p: Phase::A((a.async_match(matcher), b, c, d, e, f)) }
385    }
386}
387
388/// Future to do pattern matching of
389/// [Tuple7](../../pattern/combinators/type.Tuple7.html) pattern.
390#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
391pub struct MatchTuple7<M, A, B, C, D, E, F, G>
392where
393    M: Matcher,
394    A: AsyncMatch<M>,
395    B: AsyncMatch<M>,
396    C: AsyncMatch<M>,
397    D: AsyncMatch<M>,
398    E: AsyncMatch<M>,
399    F: AsyncMatch<M>,
400    G: AsyncMatch<M>,
401{
402    p: Phase<
403        (A::Future, B, C, D, E, F, G),
404        (B::Future, C, D, E, F, G, A::Value),
405        (C::Future, D, E, F, G, A::Value, B::Value),
406        (D::Future, E, F, G, A::Value, B::Value, C::Value),
407        (E::Future, F, G, A::Value, B::Value, C::Value, D::Value),
408        (F::Future, G, A::Value, B::Value, C::Value, D::Value, E::Value),
409        (G::Future, A::Value, B::Value, C::Value, D::Value, E::Value, F::Value),
410    >,
411}
412#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
413impl<M, A, B, C, D, E, F, G> Future for MatchTuple7<M, A, B, C, D, E, F, G>
414where
415    M: Matcher,
416    A: AsyncMatch<M>,
417    B: AsyncMatch<M>,
418    C: AsyncMatch<M>,
419    D: AsyncMatch<M>,
420    E: AsyncMatch<M>,
421    F: AsyncMatch<M>,
422    G: AsyncMatch<M>,
423{
424    type Item = (M, (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value));
425    type Error = AsyncError<M, M::Error>;
426    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
427        match self.p.take() {
428            Phase::A((mut future, b, c, d, e, f, g)) => {
429                if let Async::Ready((m, v)) = future.poll()? {
430                    self.p = Phase::B((b.async_match(m), c, d, e, f, g, v));
431                    self.poll()
432                } else {
433                    self.p = Phase::A((future, b, c, d, e, f, g));
434                    Ok(Async::NotReady)
435                }
436            }
437            Phase::B((mut future, c, d, e, f, g, a)) => {
438                if let Async::Ready((m, v)) = future.poll()? {
439                    self.p = Phase::C((c.async_match(m), d, e, f, g, a, v));
440                    self.poll()
441                } else {
442                    self.p = Phase::B((future, c, d, e, f, g, a));
443                    Ok(Async::NotReady)
444                }
445            }
446            Phase::C((mut future, d, e, f, g, a, b)) => {
447                if let Async::Ready((m, v)) = future.poll()? {
448                    self.p = Phase::D((d.async_match(m), e, f, g, a, b, v));
449                    self.poll()
450                } else {
451                    self.p = Phase::C((future, d, e, f, g, a, b));
452                    Ok(Async::NotReady)
453                }
454            }
455            Phase::D((mut future, e, f, g, a, b, c)) => {
456                if let Async::Ready((m, v)) = future.poll()? {
457                    self.p = Phase::E((e.async_match(m), f, g, a, b, c, v));
458                    self.poll()
459                } else {
460                    self.p = Phase::D((future, e, f, g, a, b, c));
461                    Ok(Async::NotReady)
462                }
463            }
464            Phase::E((mut future, f, g, a, b, c, d)) => {
465                if let Async::Ready((m, v)) = future.poll()? {
466                    self.p = Phase::F((f.async_match(m), g, a, b, c, d, v));
467                    self.poll()
468                } else {
469                    self.p = Phase::E((future, f, g, a, b, c, d));
470                    Ok(Async::NotReady)
471                }
472            }
473            Phase::F((mut future, g, a, b, c, d, e)) => {
474                if let Async::Ready((m, v)) = future.poll()? {
475                    self.p = Phase::G((g.async_match(m), a, b, c, d, e, v));
476                    self.poll()
477                } else {
478                    self.p = Phase::F((future, g, a, b, c, d, e));
479                    Ok(Async::NotReady)
480                }
481            }
482            Phase::G((mut future, a, b, c, d, e, f)) => {
483                if let Async::Ready((m, v)) = future.poll()? {
484                    Ok(Async::Ready((m, (a, b, c, d, e, f, v))))
485                } else {
486                    self.p = Phase::G((future, a, b, c, d, e, f));
487                    Ok(Async::NotReady)
488                }
489            }
490            _ => panic!("Cannot poll MatchTuple7 twice"),
491        }
492    }
493}
494impl<M, A, B, C, D, E, F, G> AsyncMatch<M> for (A, B, C, D, E, F, G)
495where
496    M: Matcher,
497    A: AsyncMatch<M>,
498    B: AsyncMatch<M>,
499    C: AsyncMatch<M>,
500    D: AsyncMatch<M>,
501    E: AsyncMatch<M>,
502    F: AsyncMatch<M>,
503    G: AsyncMatch<M>,
504{
505    type Future = MatchTuple7<M, A, B, C, D, E, F, G>;
506    fn async_match(self, matcher: M) -> Self::Future {
507        let (a, b, c, d, e, f, g) = self;
508        MatchTuple7 { p: Phase::A((a.async_match(matcher), b, c, d, e, f, g)) }
509    }
510}
511
512/// Future to do pattern matching of
513/// [Tuple8](../../pattern/combinators/type.Tuple8.html) pattern.
514#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
515pub struct MatchTuple8<M, A, B, C, D, E, F, G, H>
516where
517    M: Matcher,
518    A: AsyncMatch<M>,
519    B: AsyncMatch<M>,
520    C: AsyncMatch<M>,
521    D: AsyncMatch<M>,
522    E: AsyncMatch<M>,
523    F: AsyncMatch<M>,
524    G: AsyncMatch<M>,
525    H: AsyncMatch<M>,
526{
527    p: Phase<
528        (A::Future, B, C, D, E, F, G, H),
529        (B::Future, C, D, E, F, G, H, A::Value),
530        (C::Future, D, E, F, G, H, A::Value, B::Value),
531        (D::Future, E, F, G, H, A::Value, B::Value, C::Value),
532        (E::Future, F, G, H, A::Value, B::Value, C::Value, D::Value),
533        (F::Future, G, H, A::Value, B::Value, C::Value, D::Value, E::Value),
534        (G::Future, H, A::Value, B::Value, C::Value, D::Value, E::Value, F::Value),
535        (H::Future, A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value),
536    >,
537}
538#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
539impl<M, A, B, C, D, E, F, G, H> Future for MatchTuple8<M, A, B, C, D, E, F, G, H>
540where
541    M: Matcher,
542    A: AsyncMatch<M>,
543    B: AsyncMatch<M>,
544    C: AsyncMatch<M>,
545    D: AsyncMatch<M>,
546    E: AsyncMatch<M>,
547    F: AsyncMatch<M>,
548    G: AsyncMatch<M>,
549    H: AsyncMatch<M>,
550{
551    type Item = (M,
552     (A::Value, // NOTE: comment for `rustfmt`
553      B::Value,
554      C::Value,
555      D::Value,
556      E::Value,
557      F::Value,
558      G::Value,
559      H::Value));
560    type Error = AsyncError<M, M::Error>;
561    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
562        match self.p.take() {
563            Phase::A((mut future, b, c, d, e, f, g, h)) => {
564                if let Async::Ready((m, v)) = future.poll()? {
565                    self.p = Phase::B((b.async_match(m), c, d, e, f, g, h, v));
566                    self.poll()
567                } else {
568                    self.p = Phase::A((future, b, c, d, e, f, g, h));
569                    Ok(Async::NotReady)
570                }
571            }
572            Phase::B((mut future, c, d, e, f, g, h, a)) => {
573                if let Async::Ready((m, v)) = future.poll()? {
574                    self.p = Phase::C((c.async_match(m), d, e, f, g, h, a, v));
575                    self.poll()
576                } else {
577                    self.p = Phase::B((future, c, d, e, f, g, h, a));
578                    Ok(Async::NotReady)
579                }
580            }
581            Phase::C((mut future, d, e, f, g, h, a, b)) => {
582                if let Async::Ready((m, v)) = future.poll()? {
583                    self.p = Phase::D((d.async_match(m), e, f, g, h, a, b, v));
584                    self.poll()
585                } else {
586                    self.p = Phase::C((future, d, e, f, g, h, a, b));
587                    Ok(Async::NotReady)
588                }
589            }
590            Phase::D((mut future, e, f, g, h, a, b, c)) => {
591                if let Async::Ready((m, v)) = future.poll()? {
592                    self.p = Phase::E((e.async_match(m), f, g, h, a, b, c, v));
593                    self.poll()
594                } else {
595                    self.p = Phase::D((future, e, f, g, h, a, b, c));
596                    Ok(Async::NotReady)
597                }
598            }
599            Phase::E((mut future, f, g, h, a, b, c, d)) => {
600                if let Async::Ready((m, v)) = future.poll()? {
601                    self.p = Phase::F((f.async_match(m), g, h, a, b, c, d, v));
602                    self.poll()
603                } else {
604                    self.p = Phase::E((future, f, g, h, a, b, c, d));
605                    Ok(Async::NotReady)
606                }
607            }
608            Phase::F((mut future, g, h, a, b, c, d, e)) => {
609                if let Async::Ready((m, v)) = future.poll()? {
610                    self.p = Phase::G((g.async_match(m), h, a, b, c, d, e, v));
611                    self.poll()
612                } else {
613                    self.p = Phase::F((future, g, h, a, b, c, d, e));
614                    Ok(Async::NotReady)
615                }
616            }
617            Phase::G((mut future, h, a, b, c, d, e, f)) => {
618                if let Async::Ready((m, v)) = future.poll()? {
619                    self.p = Phase::H((h.async_match(m), a, b, c, d, e, f, v));
620                    self.poll()
621                } else {
622                    self.p = Phase::G((future, h, a, b, c, d, e, f));
623                    Ok(Async::NotReady)
624                }
625            }
626            Phase::H((mut future, a, b, c, d, e, f, g)) => {
627                if let Async::Ready((m, v)) = future.poll()? {
628                    Ok(Async::Ready((m, (a, b, c, d, e, f, g, v))))
629                } else {
630                    self.p = Phase::H((future, a, b, c, d, e, f, g));
631                    Ok(Async::NotReady)
632                }
633            }
634            _ => panic!("Cannot poll MatchTuple8 twice"),
635        }
636    }
637}
638impl<M, A, B, C, D, E, F, G, H> AsyncMatch<M> for (A, B, C, D, E, F, G, H)
639where
640    M: Matcher,
641    A: AsyncMatch<M>,
642    B: AsyncMatch<M>,
643    C: AsyncMatch<M>,
644    D: AsyncMatch<M>,
645    E: AsyncMatch<M>,
646    F: AsyncMatch<M>,
647    G: AsyncMatch<M>,
648    H: AsyncMatch<M>,
649{
650    type Future = MatchTuple8<M, A, B, C, D, E, F, G, H>;
651    fn async_match(self, matcher: M) -> Self::Future {
652        let (a, b, c, d, e, f, g, h) = self;
653        MatchTuple8 { p: Phase::A((a.async_match(matcher), b, c, d, e, f, g, h)) }
654    }
655}
656
657/// Future to do pattern matching of
658/// [Tuple9](../../pattern/combinators/type.Tuple9.html) pattern.
659#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
660pub struct MatchTuple9<M, A, B, C, D, E, F, G, H, I>
661where
662    M: Matcher,
663    A: AsyncMatch<M>,
664    B: AsyncMatch<M>,
665    C: AsyncMatch<M>,
666    D: AsyncMatch<M>,
667    E: AsyncMatch<M>,
668    F: AsyncMatch<M>,
669    G: AsyncMatch<M>,
670    H: AsyncMatch<M>,
671    I: AsyncMatch<M>,
672{
673    p: Phase<
674        (A::Future, B, C, D, E, F, G, H, I),
675        (B::Future, C, D, E, F, G, H, I, A::Value),
676        (C::Future, D, E, F, G, H, I, A::Value, B::Value),
677        (D::Future, E, F, G, H, I, A::Value, B::Value, C::Value),
678        (E::Future, F, G, H, I, A::Value, B::Value, C::Value, D::Value),
679        (F::Future, G, H, I, A::Value, B::Value, C::Value, D::Value, E::Value),
680        (G::Future, H, I, A::Value, B::Value, C::Value, D::Value, E::Value, F::Value),
681        (H::Future, I, A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value),
682        (I::Future,
683         A::Value,
684         B::Value,
685         C::Value,
686         D::Value,
687         E::Value,
688         F::Value,
689         G::Value,
690         H::Value),
691    >,
692}
693#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
694impl<M, A, B, C, D, E, F, G, H, I> Future for MatchTuple9<M, A, B, C, D, E, F, G, H, I>
695    where M: Matcher,
696          A: AsyncMatch<M>,
697          B: AsyncMatch<M>,
698          C: AsyncMatch<M>,
699          D: AsyncMatch<M>,
700          E: AsyncMatch<M>,
701          F: AsyncMatch<M>,
702          G: AsyncMatch<M>,
703          H: AsyncMatch<M>,
704          I: AsyncMatch<M>
705{
706    type Item = (M,
707     (A::Value,
708      B::Value,
709      C::Value,
710      D::Value,
711      E::Value,
712      F::Value,
713      G::Value,
714      H::Value,
715      I::Value));
716    type Error = AsyncError<M, M::Error>;
717    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
718        match self.p.take() {
719            Phase::A((mut future, b, c, d, e, f, g, h, i)) => {
720                if let Async::Ready((m, v)) = future.poll()? {
721                    self.p = Phase::B((b.async_match(m), c, d, e, f, g, h, i, v));
722                    self.poll()
723                } else {
724                    self.p = Phase::A((future, b, c, d, e, f, g, h, i));
725                    Ok(Async::NotReady)
726                }
727            }
728            Phase::B((mut future, c, d, e, f, g, h, i, a)) => {
729                if let Async::Ready((m, v)) = future.poll()? {
730                    self.p = Phase::C((c.async_match(m), d, e, f, g, h, i, a, v));
731                    self.poll()
732                } else {
733                    self.p = Phase::B((future, c, d, e, f, g, h, i, a));
734                    Ok(Async::NotReady)
735                }
736            }
737            Phase::C((mut future, d, e, f, g, h, i, a, b)) => {
738                if let Async::Ready((m, v)) = future.poll()? {
739                    self.p = Phase::D((d.async_match(m), e, f, g, h, i, a, b, v));
740                    self.poll()
741                } else {
742                    self.p = Phase::C((future, d, e, f, g, h, i, a, b));
743                    Ok(Async::NotReady)
744                }
745            }
746            Phase::D((mut future, e, f, g, h, i, a, b, c)) => {
747                if let Async::Ready((m, v)) = future.poll()? {
748                    self.p = Phase::E((e.async_match(m), f, g, h, i, a, b, c, v));
749                    self.poll()
750                } else {
751                    self.p = Phase::D((future, e, f, g, h, i, a, b, c));
752                    Ok(Async::NotReady)
753                }
754            }
755            Phase::E((mut future, f, g, h, i, a, b, c, d)) => {
756                if let Async::Ready((m, v)) = future.poll()? {
757                    self.p = Phase::F((f.async_match(m), g, h, i, a, b, c, d, v));
758                    self.poll()
759                } else {
760                    self.p = Phase::E((future, f, g, h, i, a, b, c, d));
761                    Ok(Async::NotReady)
762                }
763            }
764            Phase::F((mut future, g, h, i, a, b, c, d, e)) => {
765                if let Async::Ready((m, v)) = future.poll()? {
766                    self.p = Phase::G((g.async_match(m), h, i, a, b, c, d, e, v));
767                    self.poll()
768                } else {
769                    self.p = Phase::F((future, g, h, i, a, b, c, d, e));
770                    Ok(Async::NotReady)
771                }
772            }
773            Phase::G((mut future, h, i, a, b, c, d, e, f)) => {
774                if let Async::Ready((m, v)) = future.poll()? {
775                    self.p = Phase::H((h.async_match(m), i, a, b, c, d, e, f, v));
776                    self.poll()
777                } else {
778                    self.p = Phase::G((future, h, i, a, b, c, d, e, f));
779                    Ok(Async::NotReady)
780                }
781            }
782            Phase::H((mut future, i, a, b, c, d, e, f, g)) => {
783                if let Async::Ready((m, v)) = future.poll()? {
784                    self.p = Phase::I((i.async_match(m), a, b, c, d, e, f, g, v));
785                    self.poll()
786                } else {
787                    self.p = Phase::H((future, i, a, b, c, d, e, f, g));
788                    Ok(Async::NotReady)
789                }
790            }
791            Phase::I((mut future, a, b, c, d, e, f, g, h)) => {
792                if let Async::Ready((m, v)) = future.poll()? {
793                    Ok(Async::Ready((m, (a, b, c, d, e, f, g, h, v))))
794                } else {
795                    self.p = Phase::I((future, a, b, c, d, e, f, g, h));
796                    Ok(Async::NotReady)
797                }
798            }
799            _ => panic!("Cannot poll MatchTuple9 twice"),
800        }
801    }
802}
803impl<M, A, B, C, D, E, F, G, H, I> AsyncMatch<M> for (A, B, C, D, E, F, G, H, I)
804where
805    M: Matcher,
806    A: AsyncMatch<M>,
807    B: AsyncMatch<M>,
808    C: AsyncMatch<M>,
809    D: AsyncMatch<M>,
810    E: AsyncMatch<M>,
811    F: AsyncMatch<M>,
812    G: AsyncMatch<M>,
813    H: AsyncMatch<M>,
814    I: AsyncMatch<M>,
815{
816    type Future = MatchTuple9<M, A, B, C, D, E, F, G, H, I>;
817    fn async_match(self, matcher: M) -> Self::Future {
818        let (a, b, c, d, e, f, g, h, i) = self;
819        MatchTuple9 { p: Phase::A((a.async_match(matcher), b, c, d, e, f, g, h, i)) }
820    }
821}
822
823/// Future to do pattern matching of
824/// [Tuple10](../../pattern/combinators/type.Tuple10.html) pattern.
825#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
826pub struct MatchTuple10<M, A, B, C, D, E, F, G, H, I, J>
827where
828    M: Matcher,
829    A: AsyncMatch<M>,
830    B: AsyncMatch<M>,
831    C: AsyncMatch<M>,
832    D: AsyncMatch<M>,
833    E: AsyncMatch<M>,
834    F: AsyncMatch<M>,
835    G: AsyncMatch<M>,
836    H: AsyncMatch<M>,
837    I: AsyncMatch<M>,
838    J: AsyncMatch<M>,
839{
840    p: Phase<
841        (A::Future, B, C, D, E, F, G, H, I, J),
842        (B::Future, C, D, E, F, G, H, I, J, A::Value),
843        (C::Future, D, E, F, G, H, I, J, A::Value, B::Value),
844        (D::Future, E, F, G, H, I, J, A::Value, B::Value, C::Value),
845        (E::Future, F, G, H, I, J, A::Value, B::Value, C::Value, D::Value),
846        (F::Future, G, H, I, J, A::Value, B::Value, C::Value, D::Value, E::Value),
847        (G::Future, H, I, J, A::Value, B::Value, C::Value, D::Value, E::Value, F::Value),
848        (H::Future,
849         I,
850         J,
851         A::Value,
852         B::Value,
853         C::Value,
854         D::Value,
855         E::Value,
856         F::Value,
857         G::Value),
858        (I::Future,
859         J,
860         A::Value,
861         B::Value,
862         C::Value,
863         D::Value,
864         E::Value,
865         F::Value,
866         G::Value,
867         H::Value),
868        (J::Future,
869         A::Value,
870         B::Value,
871         C::Value,
872         D::Value,
873         E::Value,
874         F::Value,
875         G::Value,
876         H::Value,
877         I::Value),
878    >,
879}
880#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
881impl<M, A, B, C, D, E, F, G, H, I, J> Future for MatchTuple10<M, A, B, C, D, E, F, G, H, I, J>
882    where M: Matcher,
883          A: AsyncMatch<M>,
884          B: AsyncMatch<M>,
885          C: AsyncMatch<M>,
886          D: AsyncMatch<M>,
887          E: AsyncMatch<M>,
888          F: AsyncMatch<M>,
889          G: AsyncMatch<M>,
890          H: AsyncMatch<M>,
891          I: AsyncMatch<M>,
892          J: AsyncMatch<M>
893{
894    type Item = (M,
895     (A::Value,
896      B::Value,
897      C::Value,
898      D::Value,
899      E::Value,
900      F::Value,
901      G::Value,
902      H::Value,
903      I::Value,
904      J::Value));
905    type Error = AsyncError<M, M::Error>;
906    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
907        match self.p.take() {
908            Phase::A((mut future, b, c, d, e, f, g, h, i, j)) => {
909                if let Async::Ready((m, v)) = future.poll()? {
910                    self.p = Phase::B((b.async_match(m), c, d, e, f, g, h, i, j, v));
911                    self.poll()
912                } else {
913                    self.p = Phase::A((future, b, c, d, e, f, g, h, i, j));
914                    Ok(Async::NotReady)
915                }
916            }
917            Phase::B((mut future, c, d, e, f, g, h, i, j, a)) => {
918                if let Async::Ready((m, v)) = future.poll()? {
919                    self.p = Phase::C((c.async_match(m), d, e, f, g, h, i, j, a, v));
920                    self.poll()
921                } else {
922                    self.p = Phase::B((future, c, d, e, f, g, h, i, j, a));
923                    Ok(Async::NotReady)
924                }
925            }
926            Phase::C((mut future, d, e, f, g, h, i, j, a, b)) => {
927                if let Async::Ready((m, v)) = future.poll()? {
928                    self.p = Phase::D((d.async_match(m), e, f, g, h, i, j, a, b, v));
929                    self.poll()
930                } else {
931                    self.p = Phase::C((future, d, e, f, g, h, i, j, a, b));
932                    Ok(Async::NotReady)
933                }
934            }
935            Phase::D((mut future, e, f, g, h, i, j, a, b, c)) => {
936                if let Async::Ready((m, v)) = future.poll()? {
937                    self.p = Phase::E((e.async_match(m), f, g, h, i, j, a, b, c, v));
938                    self.poll()
939                } else {
940                    self.p = Phase::D((future, e, f, g, h, i, j, a, b, c));
941                    Ok(Async::NotReady)
942                }
943            }
944            Phase::E((mut future, f, g, h, i, j, a, b, c, d)) => {
945                if let Async::Ready((m, v)) = future.poll()? {
946                    self.p = Phase::F((f.async_match(m), g, h, i, j, a, b, c, d, v));
947                    self.poll()
948                } else {
949                    self.p = Phase::E((future, f, g, h, i, j, a, b, c, d));
950                    Ok(Async::NotReady)
951                }
952            }
953            Phase::F((mut future, g, h, i, j, a, b, c, d, e)) => {
954                if let Async::Ready((m, v)) = future.poll()? {
955                    self.p = Phase::G((g.async_match(m), h, i, j, a, b, c, d, e, v));
956                    self.poll()
957                } else {
958                    self.p = Phase::F((future, g, h, i, j, a, b, c, d, e));
959                    Ok(Async::NotReady)
960                }
961            }
962            Phase::G((mut future, h, i, j, a, b, c, d, e, f)) => {
963                if let Async::Ready((m, v)) = future.poll()? {
964                    self.p = Phase::H((h.async_match(m), i, j, a, b, c, d, e, f, v));
965                    self.poll()
966                } else {
967                    self.p = Phase::G((future, h, i, j, a, b, c, d, e, f));
968                    Ok(Async::NotReady)
969                }
970            }
971            Phase::H((mut future, i, j, a, b, c, d, e, f, g)) => {
972                if let Async::Ready((m, v)) = future.poll()? {
973                    self.p = Phase::I((i.async_match(m), j, a, b, c, d, e, f, g, v));
974                    self.poll()
975                } else {
976                    self.p = Phase::H((future, i, j, a, b, c, d, e, f, g));
977                    Ok(Async::NotReady)
978                }
979            }
980            Phase::I((mut future, j, a, b, c, d, e, f, g, h)) => {
981                if let Async::Ready((m, v)) = future.poll()? {
982                    self.p = Phase::J((j.async_match(m), a, b, c, d, e, f, g, h, v));
983                    self.poll()
984                } else {
985                    self.p = Phase::I((future, j, a, b, c, d, e, f, g, h));
986                    Ok(Async::NotReady)
987                }
988            }
989            Phase::J((mut future, a, b, c, d, e, f, g, h, i)) => {
990                if let Async::Ready((m, v)) = future.poll()? {
991                    Ok(Async::Ready((m, (a, b, c, d, e, f, g, h, i, v))))
992                } else {
993                    self.p = Phase::J((future, a, b, c, d, e, f, g, h, i));
994                    Ok(Async::NotReady)
995                }
996            }
997            _ => panic!("Cannot poll MatchTuple10 twice"),
998        }
999    }
1000}
1001impl<M, A, B, C, D, E, F, G, H, I, J> AsyncMatch<M> for (A, B, C, D, E, F, G, H, I, J)
1002    where M: Matcher,
1003          A: AsyncMatch<M>,
1004          B: AsyncMatch<M>,
1005          C: AsyncMatch<M>,
1006          D: AsyncMatch<M>,
1007          E: AsyncMatch<M>,
1008          F: AsyncMatch<M>,
1009          G: AsyncMatch<M>,
1010          H: AsyncMatch<M>,
1011          I: AsyncMatch<M>,
1012          J: AsyncMatch<M>
1013{
1014    type Future = MatchTuple10<M, A, B, C, D, E, F, G, H, I, J>;
1015    fn async_match(self, matcher: M) -> Self::Future {
1016        let (a, b, c, d, e, f, g, h, i, j) = self;
1017        MatchTuple10 { p: Phase::A((a.async_match(matcher), b, c, d, e, f, g, h, i, j)) }
1018    }
1019}
1020
1021#[derive(Debug)]
1022enum Phase<A, B, C = A, D = A, E = A, F = A, G = A, H = A, I = A, J = A> {
1023    A(A),
1024    B(B),
1025    C(C),
1026    D(D),
1027    E(E),
1028    F(F),
1029    G(G),
1030    H(H),
1031    I(I),
1032    J(J),
1033    Polled,
1034}
1035impl<A, B, C, D, E, F, G, H, I, J> Phase<A, B, C, D, E, F, G, H, I, J> {
1036    pub fn take(&mut self) -> Self {
1037        use std::mem;
1038        mem::replace(self, Phase::Polled)
1039    }
1040}