How to print the type of a variable in Rust? (analog of type() from Python)
Hello everyone! I just started learning Rust and encountered a debugging problem. In Python, I'm used to using `type(variable)` or `print(type(variable))` to quickly find out what data type is stored in a variable. This is very convenient when working with dynamic structures or just wanting to verify that the compiler inferred the correct type.
In Rust, of course, there is static typing, but sometimes I write code with generics or use traits, and I would like to be able to print at debug stage what specific type is obtained at runtime. For example, I have this code:
```rust
fn main() {
let x = 42;
let y = "hello";
let z = vec![1, 2, 3];
// How can I print the types of x, y, z?
// print_type(x);
// print_type(y);
// print_type(z);
}
```
I'm asking
No answers yet.
Log in to leave an answer