Macro frunk_core::hlist_pat
source · macro_rules! hlist_pat { () => { ... }; (...) => { ... }; (...$rest:pat) => { ... }; (_) => { ... }; ($a:pat) => { ... }; (_, $($tok:tt)*) => { ... }; ($a:pat, $($tok:tt)*) => { ... }; }
Expand description
Macro for pattern-matching on HLists.
Taken from https://github.com/tbu-/rust-rfcs/blob/master/text/0873-type-macros.md
§Examples
let h = hlist![13.5f32, "hello", Some(41)];
let hlist_pat![a1, a2, a3] = h;
assert_eq!(a1, 13.5f32);
assert_eq!(a2, "hello");
assert_eq!(a3, Some(41));
// Use "...tail" to match the rest of the list
let hlist_pat![b_head, ...b_tail] = h;
assert_eq!(b_head, 13.5f32);
assert_eq!(b_tail, hlist!["hello", Some(41)]);
// You can also use "..." to just ignore the rest.
let hlist_pat![c, ...] = h;
assert_eq!(c, 13.5f32);
Run