如题,代码如下:
use std::any::type_name;
fn typename<T>(_:&T){
println!("类型是:{}",type_name::<T>());
}
enum Mye<T>{
Value(T),
}
fn main() {
//输出 类型是:(i32, i32, &str, bool)
let m = (1,2,"ok",true);
typename(&m);
//输出 类型是:test1::Mye<(i32, i32, &str, bool)>
let e = Mye::Value((1,2,"ok",true));
typename(&e);
//输出 类型是:alloc::string::String
let s =String::from("rust");
typename(&s);
}