mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
24 lines
501 B
Rust
24 lines
501 B
Rust
// run-pass
|
|
#![allow(unused_macro_rules)]
|
|
|
|
/// A compile-time map from identifiers to arbitrary (heterogeneous) expressions
|
|
macro_rules! ident_map {
|
|
( $name:ident = { $($key:ident => $e:expr,)* } ) => {
|
|
macro_rules! $name {
|
|
$(
|
|
( $key ) => { $e };
|
|
)*
|
|
// Empty invocation expands to nothing. Needed when the map is empty.
|
|
() => {};
|
|
}
|
|
};
|
|
}
|
|
|
|
ident_map!(my_map = {
|
|
main => 0,
|
|
});
|
|
|
|
fn main() {
|
|
my_map!(main);
|
|
}
|