Avatar ·

How to output a variable's type in Rust? (analog of type() from Python or typeof from JS)

Hello everyone! I just started learning Rust and ran into a problem. In Python I could easily find out a variable's type using `type()`, in JavaScript — via `typeof`. How do I do this in Rust?\n\nI'm trying to debug a simple program where I'm adding numbers, but the compiler complains about type mismatch. Here's an example:\n\n```rust\nfn main() {\n let a = 10;\n let b = 3.14;\n let c = a + b; // Error!\n println!("{}", c);\n}\n```\n\nThe compiler says something about `cannot add float to integer`, but I want to first just see what types `a` and `b` have at runtime to understand what went wrong. In other languages I would just write `print(type(a))` or `console.log(typeof a)`.\n\nI tried using `std::any::type_name`, but something went wrong — the compiler complains about strange traits.