Macro muds::cons

source · []
macro_rules! cons {
    () => { ... };
    (rev[$head:tt] $($reversed:tt)*) => { ... };
    (rev[$head:expr] $($reversed:tt)*) => { ... };
    (rev[$head:pat_param] $($reversed:tt)*) => { ... };
    (rev[$head:tt, $($rest:tt)*] $($reversed:tt)*) => { ... };
    (rev[$head:expr, $($rest:tt)*] $($reversed:tt)*) => { ... };
    (rev[$head:pat_param, $($rest:tt)*] $($reversed:tt)*) => { ... };
    (..$rest:tt) => { ... };
    (..$rest:expr) => { ... };
    ($head:tt) => { ... };
    ($head:expr) => { ... };
    ($head:pat_param) => { ... };
    ($head:tt, $($tail:tt)*) => { ... };
    ($head:expr, $($tail:tt)*) => { ... };
    ($head:pat_param, $($tail:tt)*) => { ... };
}
Expand description

Constructs a Cons based on the values or identifiers passed in.

Examples

let (c1, (c2, (c3, ()))) = cons!(123f32, "hello", Some(45));
assert_eq!((c1, c2, c3), (123f32, "hello", Some(45)));

let cons!(c1, c2, c3) = cons!(123f32, "hello", Some(45));
assert_eq!(c3, Some(45));

let cons!(c1, c2, c3, ..rest) = cons!(1, 2, 3, 4, 5);
assert_eq!(rest, cons!(4, 5));

// rev[..] captures in reverse order.
let cons!(rev[c1, c2, c3, c4, c5]) = cons!(1, 2, 3, 4, 5);
assert_eq!([c1, c2, c3], [5, 4, 3]);