found a solution to print the Type (T) of a variable
https://stackoverflow.com/a/58119924
This commit is contained in:
parent
0e3e60b23e
commit
5e4c3dc119
|
@ -1,9 +1,14 @@
|
|||
fn main() {
|
||||
let v: Vec<i8> = vec![10, 20, 30];
|
||||
let mut iter = v.into_iter();
|
||||
let mut iter = v.iter();
|
||||
|
||||
println!("v[0]: {:?}", iter.next());
|
||||
|
||||
let v1: Option<i8> = iter.next();
|
||||
let v1: Option<&i8> = iter.next();
|
||||
println!("v[1]: {v1:?}");
|
||||
print_type_name(&v1);
|
||||
}
|
||||
|
||||
fn print_type_name<T>(_: &T) {
|
||||
println!("{}", std::any::type_name::<T>());
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue