I'm trying to write a macro to work on each of the types inside a tuple type. The tuple type is passed from the generic type parameter of a function to the macro.
eg
fn print_type_ids<T:'static>() { my_macro!(T); }
print_type_ids::<(i32,f32,&str)>()
should print the 3 different type ids.
But I can't match inside the Tuple Type when it is passed as a generic type param to the macro.
My code so far:
macro_rules! my_macro {
( ($($x:ty),+) ) => {
{
$(
println!("{:?}",std::any::TypeId::of::<$x>());
)+
}
};
}
fn print_type_ids<T:'static>() {
my_macro!(T); //error, no match for this
}
fn main() {
print_type_ids::<(i32,f32)>();
my_macro!((i32,f32)); //works, prints twice, once for each type
}
I found two examples that look like they should solve my problem, but failed to understand what they are doing.
let (log, operation_state_id) = serde_json::from_slice::<(String, String)>(serialized_tuple.as_bytes()).unwrap();
let t : (u32, u16) = num::Bounded::max_value();