I'd like to create a setter/getter pair of functions where the names are automatically generated based on a shared component, but I couldn't find any example of macro rules generating a new name.
Is there a way to generate code like fn get_$iden()
and SomeEnum::XX_GET_$enum_iden
?
My
mashup
crate provides a stable way to create new identifiers that works with any Rust version >= 1.15.0.No, not as of Rust 1.22.
If you can use nightly builds...
Yes:
concat_idents!(get_, $iden)
and such will allow you to create a new identifier.But no: the parser doesn't allow macro calls everywhere, so many of the places you might have sought to do this won't work. In such cases, you are sadly on your own.
fn concat_idents!(get_, $iden)(…) { … }
, for example, won't work.