Macro object_alloc_test::call_for_all_types_prefix
[−]
[src]
macro_rules! call_for_all_types_prefix { ($fn:ident, $prefix:ident $(, $arg:tt)*) => { ... }; }
Call a macro once for each type defined in the types
module.
call_for_all_types_prefix
is useful for defining something (usually test functions) once for
each type defined in the test
module. The first argument, fn
, is the name of a macro to
invoke. This macro will be invoked once for each type with its first argument being a
constructed identifier and the second argument being the type. For example,
call_for_all_types_prefix!(foo, bar)
expands to:
foo!(bar_0001_byte, $crate::types::Byte1); foo!(bar_0002_byte, $crate::types::Byte2); foo!(bar_0003_byte, $crate::types::Byte3); // ...etc
An arbitrary number of optional arguments may also be supplied; these will be
passed as additional trailing arguments in the invocation of the macro. For example,
call_for_all_types_prefix!(foo, bar, baz, blah)
expands to:
foo!(bar_0001_byte, $crate::types::Byte1, baz, blah); foo!(bar_0002_byte, $crate::types::Byte2, baz, blah); foo!(bar_0003_byte, $crate::types::Byte3, baz, blah); // ...etc
Examples
macro_rules! make_default_test { ($name:ident, $type:ty) => ( fn $name() { <$type>::default(); } ) } call_for_all_types_prefix!(make_default_test, default_test);