found a solution to print the Type (T) of a variable

https://stackoverflow.com/a/58119924
This commit is contained in:
Vincent Batts 2023-01-23 11:21:33 -05:00
parent 0e3e60b23e
commit 5e4c3dc119
47 changed files with 7 additions and 2 deletions

View File

@ -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.