# Macro std::select[−][src]

    macro_rules! select {
        (
            $($name:pat = $rx:ident.$meth:ident() => $code:expr),+
        ) => { ... };
    }

🔬 This is a nightly-only experimental API. (`mpsc_select` #27800)

A macro to select an event from a number of receivers.

This macro is used to wait for the first event to occur on a number of receivers. It places no restrictions on the types of receivers given to this macro, this can be viewed as a heterogeneous select.

# Examples

    #![feature(mpsc_select)]

    use std::thread;
    use std::sync::mpsc;

    // two placeholder functions for now
    fn long_running_thread() {}
    fn calculate_the_answer() -> u32 { 42 }

    let (tx1, rx1) = mpsc::channel();
    let (tx2, rx2) = mpsc::channel();

    thread::spawn(move|| { long_running_thread(); tx1.send(()).unwrap(); });
    thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); });

    select! {
        _ = rx1.recv() => println!("the long running thread finished first"),
        answer = rx2.recv() => {
            println!("the answer was: {}", answer.unwrap());
        }
    }Run

For more information about select, see the `std::sync::mpsc::Select` structure.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)