How do I print the type of a variable in Rust?

后端 未结 11 2234
无人共我
无人共我 2020-11-22 08:49

I have the following:

let mut my_number = 32.90;

How do I print the type of my_number?

Using type and

11条回答
  •  春和景丽
    2020-11-22 09:13

    You can also use the simple approach of using the variable in println!("{:?}", var). If Debug is not implemented for the type, you can see the type in the compiler's error message:

    mod some {
        pub struct SomeType;
    }
    
    fn main() {
        let unknown_var = some::SomeType;
        println!("{:?}", unknown_var);
    }
    

    (playpen)

    It's dirty but it works.

提交回复
热议问题