The types passed directly to the macro template correspond to what you expected, but if they are passed through another macro as ty, they no longer match:
macro_rules! mrtype {
( bool ) => ("b");
( i32 ) => ("i");
( f64 ) => ("f");
( &str ) => ("z");
( $_t:ty ) => ("o");
}
macro_rules! around {
( $t:ty ) => (mrtype!($t));
}
fn main() {
println!("{}{}{}", mrtype!(i32), around!(i32), around!(&str));
}
Prints iooinstead iiz.
Transmission ttinstead tyworks, but if you have one &str, you need 2 tts, which makes everything unnecessarily complicated.
source
share