I've been trying to write a macro to help me generate type synonyms (through traits) for closures.
macro_rules! closure_constraint {
(
$name:ident,
for< $lt:ty > FnOnce($arg:ty)
) => {
pub trait $name: for<$lt> FnOnce($arg) {}
};
}
closure_constraint!(Submit, for<'a> FnOnce(&'a str));
Sadly, this doesn't compile: Rust Playground
However, if you write this manually, or run cargo expand
and extract the code from there, then everything works.
Is there a way I can write this differently, so this compiles?