pretty self explanatory, a macro fragment that takes any keyword, this wouldn't always be useful but here's one example
Examples
macro_rules! declare_x {
($decl_kw:kw = $v:expr) => {
$decl_kw x = $v;
};
}
this is one example, here's another
// Using the `macro` keyword
macro declare_fn($($keywords:kw)*) {
$($keywords)* fn x() {}
}
Unanswered Questions
- would this be useful in libraries, i feel its only useful for those one time macros
macro_rules! impl_marker {
($($safety:kw)? $Trait:ident for $($ty:ty)*) => {$(
// we are using a variable(?) here, so a user can EASILY misuse this
$($safety:kw)? impl $Trait for $ty {}
)*};
}
- what would happen with auto, safe and default? (contextual keywords)
// #![feature(specialization)]
// same macro
macro_rules! impl_marker {
($($safety:kw)? $Trait:ident for $($ty:ty)*) => {$(
// we are using a variable(?) here, so a user can EASILY misuse this
$($safety:kw)? impl $Trait for $ty {}
)*};
}
trait MyTrait {}
impl_marker!(default MyTrait for i32);
// now what, is it ok or no?