From b23ec6ee69bd8da6fbca82ff7104e68263a24e32 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 13 Jan 2016 23:06:44 +0100 Subject: [PATCH] Nice macros. --- src/common.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/common.rs b/src/common.rs index 39294155c..c57357af8 100644 --- a/src/common.rs +++ b/src/common.rs @@ -5,3 +5,31 @@ pub use uint::*; pub use bytes::*; pub use vector::*; pub use sha3::*; + +#[macro_export] +macro_rules! map { + ( $( $x:expr => $y:expr ),* ) => { + vec![ $( ($x, $y) ),* ].into_iter().collect::>() + } +} + +#[macro_export] +macro_rules! mapx { + ( $( $x:expr => $y:expr ),* ) => { + vec![ $( ( From::from($x), From::from($y) ) ),* ].into_iter().collect::>() + } +} + +#[macro_export] +macro_rules! x { + ( $x:expr ) => { + From::from($x) + } +} + +#[macro_export] +macro_rules! xx { + ( $x:expr ) => { + From::from(From::from($x)) + } +}