tokio/macros/
select.rs

1macro_rules! doc {
2    ($select:item) => {
3        /// Waits on multiple concurrent branches, returning when the **first** branch
4        /// completes, cancelling the remaining branches.
5        ///
6        /// The `select!` macro must be used inside of async functions, closures, and
7        /// blocks.
8        ///
9        /// The `select!` macro accepts one or more branches with the following pattern:
10        ///
11        /// ```text
12        /// <pattern> = <async expression> (, if <precondition>)? => <handler>,
13        /// ```
14        ///
15        /// Additionally, the `select!` macro may include a single, optional `else`
16        /// branch, which evaluates if none of the other branches match their patterns:
17        ///
18        /// ```text
19        /// else => <expression>
20        /// ```
21        ///
22        /// The macro aggregates all `<async expression>` expressions and runs them
23        /// concurrently on the **current** task. Once the **first** expression
24        /// completes with a value that matches its `<pattern>`, the `select!` macro
25        /// returns the result of evaluating the completed branch's `<handler>`
26        /// expression.
27        ///
28        /// Additionally, each branch may include an optional `if` precondition. If the
29        /// precondition returns `false`, then the branch is disabled. The provided
30        /// `<async expression>` is still evaluated but the resulting future is never
31        /// polled. This capability is useful when using `select!` within a loop.
32        ///
33        /// The complete lifecycle of a `select!` expression is as follows:
34        ///
35        /// 1. Evaluate all provided `<precondition>` expressions. If the precondition
36        ///    returns `false`, disable the branch for the remainder of the current call
37        ///    to `select!`. Re-entering `select!` due to a loop clears the "disabled"
38        ///    state.
39        /// 2. Aggregate the `<async expression>`s from each branch, including the
40        ///    disabled ones. If the branch is disabled, `<async expression>` is still
41        ///    evaluated, but the resulting future is not polled.
42        /// 3. If **all** branches are disabled: go to step 6.
43        /// 4. Concurrently await on the results for all remaining `<async expression>`s.
44        /// 5. Once an `<async expression>` returns a value, attempt to apply the value to the
45        ///    provided `<pattern>`. If the pattern matches, evaluate the `<handler>` and return.
46        ///    If the pattern **does not** match, disable the current branch for the remainder of
47        ///    the current call to `select!`. Continue from step 3.
48        /// 6. Evaluate the `else` expression. If no else expression is provided, panic.
49        ///
50        /// # Runtime characteristics
51        ///
52        /// By running all async expressions on the current task, the expressions are
53        /// able to run **concurrently** but not in **parallel**. This means all
54        /// expressions are run on the same thread and if one branch blocks the thread,
55        /// all other expressions will be unable to continue. If parallelism is
56        /// required, spawn each async expression using [`tokio::spawn`] and pass the
57        /// join handle to `select!`.
58        ///
59        /// [`tokio::spawn`]: crate::spawn
60        ///
61        /// # Fairness
62        ///
63        /// By default, `select!` randomly picks a branch to check first. This provides
64        /// some level of fairness when calling `select!` in a loop with branches that
65        /// are always ready.
66        ///
67        /// This behavior can be overridden by adding `biased;` to the beginning of the
68        /// macro usage. See the examples for details. This will cause `select` to poll
69        /// the futures in the order they appear from top to bottom. There are a few
70        /// reasons you may want this:
71        ///
72        /// - The random number generation of `tokio::select!` has a non-zero CPU cost
73        /// - Your futures may interact in a way where known polling order is significant
74        ///
75        /// But there is an important caveat to this mode. It becomes your responsibility
76        /// to ensure that the polling order of your futures is fair. If for example you
77        /// are selecting between a stream and a shutdown future, and the stream has a
78        /// huge volume of messages and zero or nearly zero time between them, you should
79        /// place the shutdown future earlier in the `select!` list to ensure that it is
80        /// always polled, and will not be ignored due to the stream being constantly
81        /// ready.
82        ///
83        /// # Panics
84        ///
85        /// The `select!` macro panics if all branches are disabled **and** there is no
86        /// provided `else` branch. A branch is disabled when the provided `if`
87        /// precondition returns `false` **or** when the pattern does not match the
88        /// result of `<async expression>`.
89        ///
90        /// # Cancellation safety
91        ///
92        /// When using `select!` in a loop to receive messages from multiple sources,
93        /// you should make sure that the receive call is cancellation safe to avoid
94        /// losing messages. This section goes through various common methods and
95        /// describes whether they are cancel safe.  The lists in this section are not
96        /// exhaustive.
97        ///
98        /// The following methods are cancellation safe:
99        ///
100        ///  * [`tokio::sync::mpsc::Receiver::recv`](crate::sync::mpsc::Receiver::recv)
101        ///  * [`tokio::sync::mpsc::UnboundedReceiver::recv`](crate::sync::mpsc::UnboundedReceiver::recv)
102        ///  * [`tokio::sync::broadcast::Receiver::recv`](crate::sync::broadcast::Receiver::recv)
103        ///  * [`tokio::sync::watch::Receiver::changed`](crate::sync::watch::Receiver::changed)
104        ///  * [`tokio::net::TcpListener::accept`](crate::net::TcpListener::accept)
105        ///  * [`tokio::net::UnixListener::accept`](crate::net::UnixListener::accept)
106        ///  * [`tokio::signal::unix::Signal::recv`](crate::signal::unix::Signal::recv)
107        ///  * [`tokio::io::AsyncReadExt::read`](crate::io::AsyncReadExt::read) on any `AsyncRead`
108        ///  * [`tokio::io::AsyncReadExt::read_buf`](crate::io::AsyncReadExt::read_buf) on any `AsyncRead`
109        ///  * [`tokio::io::AsyncWriteExt::write`](crate::io::AsyncWriteExt::write) on any `AsyncWrite`
110        ///  * [`tokio::io::AsyncWriteExt::write_buf`](crate::io::AsyncWriteExt::write_buf) on any `AsyncWrite`
111        ///  * [`tokio_stream::StreamExt::next`](https://docs.rs/tokio-stream/0.1/tokio_stream/trait.StreamExt.html#method.next) on any `Stream`
112        ///  * [`futures::stream::StreamExt::next`](https://docs.rs/futures/0.3/futures/stream/trait.StreamExt.html#method.next) on any `Stream`
113        ///
114        /// The following methods are not cancellation safe and can lead to loss of data:
115        ///
116        ///  * [`tokio::io::AsyncReadExt::read_exact`](crate::io::AsyncReadExt::read_exact)
117        ///  * [`tokio::io::AsyncReadExt::read_to_end`](crate::io::AsyncReadExt::read_to_end)
118        ///  * [`tokio::io::AsyncReadExt::read_to_string`](crate::io::AsyncReadExt::read_to_string)
119        ///  * [`tokio::io::AsyncWriteExt::write_all`](crate::io::AsyncWriteExt::write_all)
120        ///
121        /// The following methods are not cancellation safe because they use a queue for
122        /// fairness and cancellation makes you lose your place in the queue:
123        ///
124        ///  * [`tokio::sync::Mutex::lock`](crate::sync::Mutex::lock)
125        ///  * [`tokio::sync::RwLock::read`](crate::sync::RwLock::read)
126        ///  * [`tokio::sync::RwLock::write`](crate::sync::RwLock::write)
127        ///  * [`tokio::sync::Semaphore::acquire`](crate::sync::Semaphore::acquire)
128        ///  * [`tokio::sync::Notify::notified`](crate::sync::Notify::notified)
129        ///
130        /// To determine whether your own methods are cancellation safe, look for the
131        /// location of uses of `.await`. This is because when an asynchronous method is
132        /// cancelled, that always happens at an `.await`. If your function behaves
133        /// correctly even if it is restarted while waiting at an `.await`, then it is
134        /// cancellation safe.
135        ///
136        /// Cancellation safety can be defined in the following way: If you have a
137        /// future that has not yet completed, then it must be a no-op to drop that
138        /// future and recreate it. This definition is motivated by the situation where
139        /// a `select!` is used in a loop. Without this guarantee, you would lose your
140        /// progress when another branch completes and you restart the `select!` by
141        /// going around the loop.
142        ///
143        /// Be aware that cancelling something that is not cancellation safe is not
144        /// necessarily wrong. For example, if you are cancelling a task because the
145        /// application is shutting down, then you probably don't care that partially
146        /// read data is lost.
147        ///
148        /// # Examples
149        ///
150        /// Basic select with two branches.
151        ///
152        /// ```
153        /// async fn do_stuff_async() {
154        ///     // async work
155        /// }
156        ///
157        /// async fn more_async_work() {
158        ///     // more here
159        /// }
160        ///
161        /// #[tokio::main]
162        /// async fn main() {
163        ///     tokio::select! {
164        ///         _ = do_stuff_async() => {
165        ///             println!("do_stuff_async() completed first")
166        ///         }
167        ///         _ = more_async_work() => {
168        ///             println!("more_async_work() completed first")
169        ///         }
170        ///     };
171        /// }
172        /// ```
173        ///
174        /// Basic stream selecting.
175        ///
176        /// ```
177        /// use tokio_stream::{self as stream, StreamExt};
178        ///
179        /// #[tokio::main]
180        /// async fn main() {
181        ///     let mut stream1 = stream::iter(vec![1, 2, 3]);
182        ///     let mut stream2 = stream::iter(vec![4, 5, 6]);
183        ///
184        ///     let next = tokio::select! {
185        ///         v = stream1.next() => v.unwrap(),
186        ///         v = stream2.next() => v.unwrap(),
187        ///     };
188        ///
189        ///     assert!(next == 1 || next == 4);
190        /// }
191        /// ```
192        ///
193        /// Collect the contents of two streams. In this example, we rely on pattern
194        /// matching and the fact that `stream::iter` is "fused", i.e. once the stream
195        /// is complete, all calls to `next()` return `None`.
196        ///
197        /// ```
198        /// use tokio_stream::{self as stream, StreamExt};
199        ///
200        /// #[tokio::main]
201        /// async fn main() {
202        ///     let mut stream1 = stream::iter(vec![1, 2, 3]);
203        ///     let mut stream2 = stream::iter(vec![4, 5, 6]);
204        ///
205        ///     let mut values = vec![];
206        ///
207        ///     loop {
208        ///         tokio::select! {
209        ///             Some(v) = stream1.next() => values.push(v),
210        ///             Some(v) = stream2.next() => values.push(v),
211        ///             else => break,
212        ///         }
213        ///     }
214        ///
215        ///     values.sort();
216        ///     assert_eq!(&[1, 2, 3, 4, 5, 6], &values[..]);
217        /// }
218        /// ```
219        ///
220        /// Using the same future in multiple `select!` expressions can be done by passing
221        /// a reference to the future. Doing so requires the future to be [`Unpin`]. A
222        /// future can be made [`Unpin`] by either using [`Box::pin`] or stack pinning.
223        ///
224        /// [`Unpin`]: std::marker::Unpin
225        /// [`Box::pin`]: std::boxed::Box::pin
226        ///
227        /// Here, a stream is consumed for at most 1 second.
228        ///
229        /// ```
230        /// use tokio_stream::{self as stream, StreamExt};
231        /// use tokio::time::{self, Duration};
232        ///
233        /// #[tokio::main]
234        /// async fn main() {
235        ///     let mut stream = stream::iter(vec![1, 2, 3]);
236        ///     let sleep = time::sleep(Duration::from_secs(1));
237        ///     tokio::pin!(sleep);
238        ///
239        ///     loop {
240        ///         tokio::select! {
241        ///             maybe_v = stream.next() => {
242        ///                 if let Some(v) = maybe_v {
243        ///                     println!("got = {}", v);
244        ///                 } else {
245        ///                     break;
246        ///                 }
247        ///             }
248        ///             _ = &mut sleep => {
249        ///                 println!("timeout");
250        ///                 break;
251        ///             }
252        ///         }
253        ///     }
254        /// }
255        /// ```
256        ///
257        /// Joining two values using `select!`.
258        ///
259        /// ```
260        /// use tokio::sync::oneshot;
261        ///
262        /// #[tokio::main]
263        /// async fn main() {
264        ///     let (tx1, mut rx1) = oneshot::channel();
265        ///     let (tx2, mut rx2) = oneshot::channel();
266        ///
267        ///     tokio::spawn(async move {
268        ///         tx1.send("first").unwrap();
269        ///     });
270        ///
271        ///     tokio::spawn(async move {
272        ///         tx2.send("second").unwrap();
273        ///     });
274        ///
275        ///     let mut a = None;
276        ///     let mut b = None;
277        ///
278        ///     while a.is_none() || b.is_none() {
279        ///         tokio::select! {
280        ///             v1 = (&mut rx1), if a.is_none() => a = Some(v1.unwrap()),
281        ///             v2 = (&mut rx2), if b.is_none() => b = Some(v2.unwrap()),
282        ///         }
283        ///     }
284        ///
285        ///     let res = (a.unwrap(), b.unwrap());
286        ///
287        ///     assert_eq!(res.0, "first");
288        ///     assert_eq!(res.1, "second");
289        /// }
290        /// ```
291        ///
292        /// Using the `biased;` mode to control polling order.
293        ///
294        /// ```
295        /// #[tokio::main]
296        /// async fn main() {
297        ///     let mut count = 0u8;
298        ///
299        ///     loop {
300        ///         tokio::select! {
301        ///             // If you run this example without `biased;`, the polling order is
302        ///             // pseudo-random, and the assertions on the value of count will
303        ///             // (probably) fail.
304        ///             biased;
305        ///
306        ///             _ = async {}, if count < 1 => {
307        ///                 count += 1;
308        ///                 assert_eq!(count, 1);
309        ///             }
310        ///             _ = async {}, if count < 2 => {
311        ///                 count += 1;
312        ///                 assert_eq!(count, 2);
313        ///             }
314        ///             _ = async {}, if count < 3 => {
315        ///                 count += 1;
316        ///                 assert_eq!(count, 3);
317        ///             }
318        ///             _ = async {}, if count < 4 => {
319        ///                 count += 1;
320        ///                 assert_eq!(count, 4);
321        ///             }
322        ///
323        ///             else => {
324        ///                 break;
325        ///             }
326        ///         };
327        ///     }
328        /// }
329        /// ```
330        ///
331        /// ## Avoid racy `if` preconditions
332        ///
333        /// Given that `if` preconditions are used to disable `select!` branches, some
334        /// caution must be used to avoid missing values.
335        ///
336        /// For example, here is **incorrect** usage of `sleep` with `if`. The objective
337        /// is to repeatedly run an asynchronous task for up to 50 milliseconds.
338        /// However, there is a potential for the `sleep` completion to be missed.
339        ///
340        /// ```no_run,should_panic
341        /// use tokio::time::{self, Duration};
342        ///
343        /// async fn some_async_work() {
344        ///     // do work
345        /// }
346        ///
347        /// #[tokio::main]
348        /// async fn main() {
349        ///     let sleep = time::sleep(Duration::from_millis(50));
350        ///     tokio::pin!(sleep);
351        ///
352        ///     while !sleep.is_elapsed() {
353        ///         tokio::select! {
354        ///             _ = &mut sleep, if !sleep.is_elapsed() => {
355        ///                 println!("operation timed out");
356        ///             }
357        ///             _ = some_async_work() => {
358        ///                 println!("operation completed");
359        ///             }
360        ///         }
361        ///     }
362        ///
363        ///     panic!("This example shows how not to do it!");
364        /// }
365        /// ```
366        ///
367        /// In the above example, `sleep.is_elapsed()` may return `true` even if
368        /// `sleep.poll()` never returned `Ready`. This opens up a potential race
369        /// condition where `sleep` expires between the `while !sleep.is_elapsed()`
370        /// check and the call to `select!` resulting in the `some_async_work()` call to
371        /// run uninterrupted despite the sleep having elapsed.
372        ///
373        /// One way to write the above example without the race would be:
374        ///
375        /// ```
376        /// use tokio::time::{self, Duration};
377        ///
378        /// async fn some_async_work() {
379        /// # time::sleep(Duration::from_millis(10)).await;
380        ///     // do work
381        /// }
382        ///
383        /// #[tokio::main]
384        /// async fn main() {
385        ///     let sleep = time::sleep(Duration::from_millis(50));
386        ///     tokio::pin!(sleep);
387        ///
388        ///     loop {
389        ///         tokio::select! {
390        ///             _ = &mut sleep => {
391        ///                 println!("operation timed out");
392        ///                 break;
393        ///             }
394        ///             _ = some_async_work() => {
395        ///                 println!("operation completed");
396        ///             }
397        ///         }
398        ///     }
399        /// }
400        /// ```
401        #[macro_export]
402        #[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
403        $select
404    };
405}
406
407#[cfg(doc)]
408doc! {macro_rules! select {
409    {
410        $(
411            biased;
412        )?
413        $(
414            $bind:pat = $fut:expr $(, if $cond:expr)? => $handler:expr,
415        )*
416        $(
417            else => $els:expr $(,)?
418        )?
419    } => {
420        unimplemented!()
421    };
422}}
423
424#[cfg(not(doc))]
425doc! {macro_rules! select {
426    // Uses a declarative macro to do **most** of the work. While it is possible
427    // to implement fully with a declarative macro, a procedural macro is used
428    // to enable improved error messages.
429    //
430    // The macro is structured as a tt-muncher. All branches are processed and
431    // normalized. Once the input is normalized, it is passed to the top-most
432    // rule. When entering the macro, `@{ }` is inserted at the front. This is
433    // used to collect the normalized input.
434    //
435    // The macro only recurses once per branch. This allows using `select!`
436    // without requiring the user to increase the recursion limit.
437
438    // All input is normalized, now transform.
439    (@ {
440        // The index of the future to poll first (in bias mode), or the RNG
441        // expression to use to pick a future to poll first.
442        start=$start:expr;
443
444        // One `_` for each branch in the `select!` macro. Passing this to
445        // `count!` converts $skip to an integer.
446        ( $($count:tt)* )
447
448        // Normalized select branches. `( $skip )` is a set of `_` characters.
449        // There is one `_` for each select branch **before** this one. Given
450        // that all input futures are stored in a tuple, $skip is useful for
451        // generating a pattern to reference the future for the current branch.
452        // $skip is also used as an argument to `count!`, returning the index of
453        // the current select branch.
454        $( ( $($skip:tt)* ) $bind:pat = $fut:expr, if $c:expr => $handle:expr, )+
455
456        // Fallback expression used when all select branches have been disabled.
457        ; $else:expr
458
459    }) => {{
460        // Enter a context where stable "function-like" proc macros can be used.
461        //
462        // This module is defined within a scope and should not leak out of this
463        // macro.
464        #[doc(hidden)]
465        mod __tokio_select_util {
466            // Generate an enum with one variant per select branch
467            $crate::select_priv_declare_output_enum!( ( $($count)* ) );
468        }
469
470        // `tokio::macros::support` is a public, but doc(hidden) module
471        // including a re-export of all types needed by this macro.
472        use $crate::macros::support::Future;
473        use $crate::macros::support::Pin;
474        use $crate::macros::support::Poll::{Ready, Pending};
475
476        const BRANCHES: u32 = $crate::count!( $($count)* );
477
478        let mut disabled: __tokio_select_util::Mask = Default::default();
479
480        // First, invoke all the pre-conditions. For any that return true,
481        // set the appropriate bit in `disabled`.
482        $(
483            if !$c {
484                let mask: __tokio_select_util::Mask = 1 << $crate::count!( $($skip)* );
485                disabled |= mask;
486            }
487        )*
488
489        // Create a scope to separate polling from handling the output. This
490        // adds borrow checker flexibility when using the macro.
491        let mut output = {
492            // Store each future directly first (that is, without wrapping the future in a call to
493            // `IntoFuture::into_future`). This allows the `$fut` expression to make use of
494            // temporary lifetime extension.
495            //
496            // https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
497            let futures_init = ($( $fut, )+);
498
499            // Safety: Nothing must be moved out of `futures`. This is to
500            // satisfy the requirement of `Pin::new_unchecked` called below.
501            //
502            // We can't use the `pin!` macro for this because `futures` is a
503            // tuple and the standard library provides no way to pin-project to
504            // the fields of a tuple.
505            let mut futures = ($( $crate::macros::support::IntoFuture::into_future(
506                        $crate::count_field!( futures_init.$($skip)* )
507            ),)+);
508
509            // This assignment makes sure that the `poll_fn` closure only has a
510            // reference to the futures, instead of taking ownership of them.
511            // This mitigates the issue described in
512            // <https://internals.rust-lang.org/t/surprising-soundness-trouble-around-pollfn/17484>
513            let mut futures = &mut futures;
514
515            $crate::macros::support::poll_fn(|cx| {
516                // Track if any branch returns pending. If no branch completes
517                // **or** returns pending, this implies that all branches are
518                // disabled.
519                let mut is_pending = false;
520
521                // Choose a starting index to begin polling the futures at. In
522                // practice, this will either be a pseudo-randomly generated
523                // number by default, or the constant 0 if `biased;` is
524                // supplied.
525                let start = $start;
526
527                for i in 0..BRANCHES {
528                    let branch;
529                    #[allow(clippy::modulo_one)]
530                    {
531                        branch = (start + i) % BRANCHES;
532                    }
533                    match branch {
534                        $(
535                            #[allow(unreachable_code)]
536                            $crate::count!( $($skip)* ) => {
537                                // First, if the future has previously been
538                                // disabled, do not poll it again. This is done
539                                // by checking the associated bit in the
540                                // `disabled` bit field.
541                                let mask = 1 << branch;
542
543                                if disabled & mask == mask {
544                                    // The future has been disabled.
545                                    continue;
546                                }
547
548                                // Extract the future for this branch from the
549                                // tuple
550                                let ( $($skip,)* fut, .. ) = &mut *futures;
551
552                                // Safety: future is stored on the stack above
553                                // and never moved.
554                                let mut fut = unsafe { Pin::new_unchecked(fut) };
555
556                                // Try polling it
557                                let out = match Future::poll(fut, cx) {
558                                    Ready(out) => out,
559                                    Pending => {
560                                        // Track that at least one future is
561                                        // still pending and continue polling.
562                                        is_pending = true;
563                                        continue;
564                                    }
565                                };
566
567                                // Disable the future from future polling.
568                                disabled |= mask;
569
570                                // The future returned a value, check if matches
571                                // the specified pattern.
572                                #[allow(unused_variables)]
573                                #[allow(unused_mut)]
574                                match &out {
575                                    $crate::select_priv_clean_pattern!($bind) => {}
576                                    _ => continue,
577                                }
578
579                                // The select is complete, return the value
580                                return Ready($crate::select_variant!(__tokio_select_util::Out, ($($skip)*))(out));
581                            }
582                        )*
583                        _ => unreachable!("reaching this means there probably is an off by one bug"),
584                    }
585                }
586
587                if is_pending {
588                    Pending
589                } else {
590                    // All branches have been disabled.
591                    Ready(__tokio_select_util::Out::Disabled)
592                }
593            }).await
594        };
595
596        match output {
597            $(
598                $crate::select_variant!(__tokio_select_util::Out, ($($skip)*) ($bind)) => $handle,
599            )*
600            __tokio_select_util::Out::Disabled => $else,
601            _ => unreachable!("failed to match bind"),
602        }
603    }};
604
605    // ==== Normalize =====
606
607    // These rules match a single `select!` branch and normalize it for
608    // processing by the first rule.
609
610    (@ { start=$start:expr; $($t:tt)* } ) => {
611        // No `else` branch
612        $crate::select!(@{ start=$start; $($t)*; panic!("all branches are disabled and there is no else branch") })
613    };
614    (@ { start=$start:expr; $($t:tt)* } else => $else:expr $(,)?) => {
615        $crate::select!(@{ start=$start; $($t)*; $else })
616    };
617    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr, if $c:expr => $h:block, $($r:tt)* ) => {
618        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if $c => $h, } $($r)*)
619    };
620    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:block, $($r:tt)* ) => {
621        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if true => $h, } $($r)*)
622    };
623    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr, if $c:expr => $h:block $($r:tt)* ) => {
624        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if $c => $h, } $($r)*)
625    };
626    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:block $($r:tt)* ) => {
627        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if true => $h, } $($r)*)
628    };
629    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr, if $c:expr => $h:expr ) => {
630        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if $c => $h, })
631    };
632    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:expr ) => {
633        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if true => $h, })
634    };
635    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr, if $c:expr => $h:expr, $($r:tt)* ) => {
636        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if $c => $h, } $($r)*)
637    };
638    (@ { start=$start:expr; ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:expr, $($r:tt)* ) => {
639        $crate::select!(@{ start=$start; ($($s)* _) $($t)* ($($s)*) $p = $f, if true => $h, } $($r)*)
640    };
641
642    // ===== Entry point =====
643
644    ($(biased;)? else => $else:expr $(,)? ) => {{
645        $else
646    }};
647
648    (biased; $p:pat = $($t:tt)* ) => {
649        $crate::select!(@{ start=0; () } $p = $($t)*)
650    };
651
652    ( $p:pat = $($t:tt)* ) => {
653        // Randomly generate a starting point. This makes `select!` a bit more
654        // fair and avoids always polling the first future.
655        $crate::select!(@{ start={ $crate::macros::support::thread_rng_n(BRANCHES) }; () } $p = $($t)*)
656    };
657
658    () => {
659        compile_error!("select! requires at least one branch.")
660    };
661}}
662
663// And here... we manually list out matches for up to 64 branches... I'm not
664// happy about it either, but this is how we manage to use a declarative macro!
665
666#[macro_export]
667#[doc(hidden)]
668macro_rules! count {
669    () => {
670        0
671    };
672    (_) => {
673        1
674    };
675    (_ _) => {
676        2
677    };
678    (_ _ _) => {
679        3
680    };
681    (_ _ _ _) => {
682        4
683    };
684    (_ _ _ _ _) => {
685        5
686    };
687    (_ _ _ _ _ _) => {
688        6
689    };
690    (_ _ _ _ _ _ _) => {
691        7
692    };
693    (_ _ _ _ _ _ _ _) => {
694        8
695    };
696    (_ _ _ _ _ _ _ _ _) => {
697        9
698    };
699    (_ _ _ _ _ _ _ _ _ _) => {
700        10
701    };
702    (_ _ _ _ _ _ _ _ _ _ _) => {
703        11
704    };
705    (_ _ _ _ _ _ _ _ _ _ _ _) => {
706        12
707    };
708    (_ _ _ _ _ _ _ _ _ _ _ _ _) => {
709        13
710    };
711    (_ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
712        14
713    };
714    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
715        15
716    };
717    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
718        16
719    };
720    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
721        17
722    };
723    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
724        18
725    };
726    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
727        19
728    };
729    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
730        20
731    };
732    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
733        21
734    };
735    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
736        22
737    };
738    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
739        23
740    };
741    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
742        24
743    };
744    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
745        25
746    };
747    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
748        26
749    };
750    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
751        27
752    };
753    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
754        28
755    };
756    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
757        29
758    };
759    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
760        30
761    };
762    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
763        31
764    };
765    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
766        32
767    };
768    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
769        33
770    };
771    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
772        34
773    };
774    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
775        35
776    };
777    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
778        36
779    };
780    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
781        37
782    };
783    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
784        38
785    };
786    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
787        39
788    };
789    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
790        40
791    };
792    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
793        41
794    };
795    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
796        42
797    };
798    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
799        43
800    };
801    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
802        44
803    };
804    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
805        45
806    };
807    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
808        46
809    };
810    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
811        47
812    };
813    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
814        48
815    };
816    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
817        49
818    };
819    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
820        50
821    };
822    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
823        51
824    };
825    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
826        52
827    };
828    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
829        53
830    };
831    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
832        54
833    };
834    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
835        55
836    };
837    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
838        56
839    };
840    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
841        57
842    };
843    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
844        58
845    };
846    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
847        59
848    };
849    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
850        60
851    };
852    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
853        61
854    };
855    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
856        62
857    };
858    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
859        63
860    };
861    (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
862        64
863    };
864}
865
866#[macro_export]
867#[doc(hidden)]
868macro_rules! count_field {
869    ($var:ident. ) => {
870        $var.0
871    };
872    ($var:ident. _) => {
873        $var.1
874    };
875    ($var:ident. _ _) => {
876        $var.2
877    };
878    ($var:ident. _ _ _) => {
879        $var.3
880    };
881    ($var:ident. _ _ _ _) => {
882        $var.4
883    };
884    ($var:ident. _ _ _ _ _) => {
885        $var.5
886    };
887    ($var:ident. _ _ _ _ _ _) => {
888        $var.6
889    };
890    ($var:ident. _ _ _ _ _ _ _) => {
891        $var.7
892    };
893    ($var:ident. _ _ _ _ _ _ _ _) => {
894        $var.8
895    };
896    ($var:ident. _ _ _ _ _ _ _ _ _) => {
897        $var.9
898    };
899    ($var:ident. _ _ _ _ _ _ _ _ _ _) => {
900        $var.10
901    };
902    ($var:ident. _ _ _ _ _ _ _ _ _ _ _) => {
903        $var.11
904    };
905    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _) => {
906        $var.12
907    };
908    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _) => {
909        $var.13
910    };
911    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
912        $var.14
913    };
914    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
915        $var.15
916    };
917    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
918        $var.16
919    };
920    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
921        $var.17
922    };
923    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
924        $var.18
925    };
926    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
927        $var.19
928    };
929    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
930        $var.20
931    };
932    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
933        $var.21
934    };
935    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
936        $var.22
937    };
938    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
939        $var.23
940    };
941    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
942        $var.24
943    };
944    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
945        $var.25
946    };
947    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
948        $var.26
949    };
950    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
951        $var.27
952    };
953    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
954        $var.28
955    };
956    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
957        $var.29
958    };
959    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
960        $var.30
961    };
962    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
963        $var.31
964    };
965    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
966        $var.32
967    };
968    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
969        $var.33
970    };
971    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
972        $var.34
973    };
974    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
975        $var.35
976    };
977    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
978        $var.36
979    };
980    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
981        $var.37
982    };
983    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
984        $var.38
985    };
986    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
987        $var.39
988    };
989    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
990        $var.40
991    };
992    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
993        $var.41
994    };
995    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
996        $var.42
997    };
998    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
999        $var.43
1000    };
1001    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1002        $var.44
1003    };
1004    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1005        $var.45
1006    };
1007    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1008        $var.46
1009    };
1010    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1011        $var.47
1012    };
1013    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1014        $var.48
1015    };
1016    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1017        $var.49
1018    };
1019    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1020        $var.50
1021    };
1022    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1023        $var.51
1024    };
1025    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1026        $var.52
1027    };
1028    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1029        $var.53
1030    };
1031    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1032        $var.54
1033    };
1034    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1035        $var.55
1036    };
1037    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1038        $var.56
1039    };
1040    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1041        $var.57
1042    };
1043    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1044        $var.58
1045    };
1046    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1047        $var.59
1048    };
1049    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1050        $var.60
1051    };
1052    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1053        $var.61
1054    };
1055    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1056        $var.62
1057    };
1058    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1059        $var.63
1060    };
1061    ($var:ident. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) => {
1062        $var.64
1063    };
1064}
1065
1066#[macro_export]
1067#[doc(hidden)]
1068macro_rules! select_variant {
1069    ($($p:ident)::*, () $($t:tt)*) => {
1070        $($p)::*::_0 $($t)*
1071    };
1072    ($($p:ident)::*, (_) $($t:tt)*) => {
1073        $($p)::*::_1 $($t)*
1074    };
1075    ($($p:ident)::*, (_ _) $($t:tt)*) => {
1076        $($p)::*::_2 $($t)*
1077    };
1078    ($($p:ident)::*, (_ _ _) $($t:tt)*) => {
1079        $($p)::*::_3 $($t)*
1080    };
1081    ($($p:ident)::*, (_ _ _ _) $($t:tt)*) => {
1082        $($p)::*::_4 $($t)*
1083    };
1084    ($($p:ident)::*, (_ _ _ _ _) $($t:tt)*) => {
1085        $($p)::*::_5 $($t)*
1086    };
1087    ($($p:ident)::*, (_ _ _ _ _ _) $($t:tt)*) => {
1088        $($p)::*::_6 $($t)*
1089    };
1090    ($($p:ident)::*, (_ _ _ _ _ _ _) $($t:tt)*) => {
1091        $($p)::*::_7 $($t)*
1092    };
1093    ($($p:ident)::*, (_ _ _ _ _ _ _ _) $($t:tt)*) => {
1094        $($p)::*::_8 $($t)*
1095    };
1096    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1097        $($p)::*::_9 $($t)*
1098    };
1099    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1100        $($p)::*::_10 $($t)*
1101    };
1102    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1103        $($p)::*::_11 $($t)*
1104    };
1105    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1106        $($p)::*::_12 $($t)*
1107    };
1108    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1109        $($p)::*::_13 $($t)*
1110    };
1111    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1112        $($p)::*::_14 $($t)*
1113    };
1114    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1115        $($p)::*::_15 $($t)*
1116    };
1117    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1118        $($p)::*::_16 $($t)*
1119    };
1120    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1121        $($p)::*::_17 $($t)*
1122    };
1123    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1124        $($p)::*::_18 $($t)*
1125    };
1126    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1127        $($p)::*::_19 $($t)*
1128    };
1129    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1130        $($p)::*::_20 $($t)*
1131    };
1132    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1133        $($p)::*::_21 $($t)*
1134    };
1135    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1136        $($p)::*::_22 $($t)*
1137    };
1138    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1139        $($p)::*::_23 $($t)*
1140    };
1141    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1142        $($p)::*::_24 $($t)*
1143    };
1144    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1145        $($p)::*::_25 $($t)*
1146    };
1147    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1148        $($p)::*::_26 $($t)*
1149    };
1150    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1151        $($p)::*::_27 $($t)*
1152    };
1153    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1154        $($p)::*::_28 $($t)*
1155    };
1156    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1157        $($p)::*::_29 $($t)*
1158    };
1159    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1160        $($p)::*::_30 $($t)*
1161    };
1162    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1163        $($p)::*::_31 $($t)*
1164    };
1165    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1166        $($p)::*::_32 $($t)*
1167    };
1168    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1169        $($p)::*::_33 $($t)*
1170    };
1171    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1172        $($p)::*::_34 $($t)*
1173    };
1174    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1175        $($p)::*::_35 $($t)*
1176    };
1177    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1178        $($p)::*::_36 $($t)*
1179    };
1180    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1181        $($p)::*::_37 $($t)*
1182    };
1183    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1184        $($p)::*::_38 $($t)*
1185    };
1186    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1187        $($p)::*::_39 $($t)*
1188    };
1189    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1190        $($p)::*::_40 $($t)*
1191    };
1192    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1193        $($p)::*::_41 $($t)*
1194    };
1195    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1196        $($p)::*::_42 $($t)*
1197    };
1198    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1199        $($p)::*::_43 $($t)*
1200    };
1201    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1202        $($p)::*::_44 $($t)*
1203    };
1204    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1205        $($p)::*::_45 $($t)*
1206    };
1207    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1208        $($p)::*::_46 $($t)*
1209    };
1210    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1211        $($p)::*::_47 $($t)*
1212    };
1213    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1214        $($p)::*::_48 $($t)*
1215    };
1216    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1217        $($p)::*::_49 $($t)*
1218    };
1219    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1220        $($p)::*::_50 $($t)*
1221    };
1222    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1223        $($p)::*::_51 $($t)*
1224    };
1225    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1226        $($p)::*::_52 $($t)*
1227    };
1228    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1229        $($p)::*::_53 $($t)*
1230    };
1231    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1232        $($p)::*::_54 $($t)*
1233    };
1234    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1235        $($p)::*::_55 $($t)*
1236    };
1237    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1238        $($p)::*::_56 $($t)*
1239    };
1240    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1241        $($p)::*::_57 $($t)*
1242    };
1243    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1244        $($p)::*::_58 $($t)*
1245    };
1246    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1247        $($p)::*::_59 $($t)*
1248    };
1249    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1250        $($p)::*::_60 $($t)*
1251    };
1252    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1253        $($p)::*::_61 $($t)*
1254    };
1255    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1256        $($p)::*::_62 $($t)*
1257    };
1258    ($($p:ident)::*, (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) $($t:tt)*) => {
1259        $($p)::*::_63 $($t)*
1260    };
1261}