diff --git a/src/macros.rs b/src/macros.rs index 7777d1438c26ff8c770480bee68c179d5490e364..1d50f6571be4b313e50a9805c37d2cf393500373 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -18,4 +18,17 @@ macro_rules! dbg_code { ($code:stmt) => { #[cfg(debug_assertions)] $code } +} + +// Given a function name, return type and variant, will generate the all-so +// common `union_value.as_variant()` method. +macro_rules! union_cast_method_impl { + ($func_name:ident, $ret_type:ty, $variant:path) => { + fn $func_name(&self) -> &$ret_type { + match self { + $variant(content) => return content, + _ => unreachable!(), + } + } + } } \ No newline at end of file