I'm trying to write a macro like this:
macro_rules! impl_numeric_cast_methods {
($($ty:ty)*) => {
$(
fn from_$ty(v: $ty) -> Self {
v as Self
}
)*
}
}
The from_$ty
bit doesn't work due to macro hygiene. I found that if $ty
was an ident
then I could (on unstable) possibly use concat_idents!
except that that apparently doesn't work either.
There's a blog post about this issue and future plans to fix it, but my question is: how can I do this at all in today's Rust stable (1.15)? Is there a workaround?