Hi !
Quick post today to share how to find a variable data type in Rust. As far as I understand, we can use several ways to do this. In example, we can use these 2 std functions:
use std::any::type_name function
use std::intrinsics::type_name
The full sample code below create 2 vectors with different data, and print the data type of the vector, and of some of the vectorβ elements. This is the output:
Compiling datatype01 v0.1.0 (C:\src\labs\RustLabs\datatype01)
Finished dev [unoptimized + debuginfo] target(s) in 0.55s
Running `target\debug\datatype01.exe`
alloc::vec::Vec<char>
char
i32
Sample Source Code
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
Top comments (1)
It's so simple... but so usefull.