How do I print the type of a variable in Rust?
@lebyy▲ 0 net votes
Problem: I have the following: let mut my_number = 32.90; How do I print the type of my_number ? Using type and type_of did not work. Is there another way I can print the number's type? Fix (from the top answer): You can use the std::any::type_name function. This doesn't need a nightly compiler or an external crate, and the results are quite correct: fn print_type_of<T>(_: &T) { println!("{}", std::any::type_name::<T>()); } fn main() { let s = Be warned: as said in the documentation, this information must be used for a debug…