[][src]Macro tuple_list::tuple_list

macro_rules! tuple_list {
    () => { ... };
    ($i:ident) => { ... };
    ($i:ident,) => { ... };
    ($i:ident, $($e:ident),*) => { ... };
    ($i:ident, $($e:ident),*,) => { ... };
    ($i:expr) => { ... };
    ($i:expr,) => { ... };
    ($i:expr, $($e:expr),*) => { ... };
    ($i:expr, $($e:expr),*,) => { ... };
}

Macro creating tuple list values from list of expressions.

Examples

Main use of this macro is to create tuple list values:

use tuple_list::tuple_list;
 
let list = tuple_list!(10, false, "foo");
 
assert_eq!(
  list,
  (10, (false, ("foo", ()))),
)
Run

Aside from that, tuple_list! can sometime be used to define trivial types, but using macro tuple_list_type! is recommended instead:

// Trivial types work just fine with `tuple_list!`.
let list: tuple_list_type!(i32, bool, String) = Default::default();
 
// More complex types will fail when using `tuple_list!`,
// but will work with `tuple_list_type!`.
use tuple_list::tuple_list_type;
 
let list: tuple_list_type!(
    &'static str,
    HashMap<i32, i32>,
    <std::vec::Vec<bool> as IntoIterator>::Item,
) = tuple_list!("foo", HashMap::new(), false);
Run

It can also be used to unpack tuples:

let tuple_list!(a, b, c) = tuple_list!(10, false, "foo");
 
assert_eq!(a, 10);
assert_eq!(b, false);
assert_eq!(c, "foo");
Run

Unfortunately, due to Rust macro limitations only simple, non-nested match patterns are supported.