fn print_type_of<T>(_: &T) { println!("The type is: {}", type_name::<T>()); } Example use std::any::type_name; fn print_type_of<T>(_: &T) { println!("The type is: {}", type_name::<T>()); } fn main() { let a = String::from("Gate"); let ref b = ...
fn print_type_name<T>(_val: &T) { println!("{}", std::any::type_name::<T>()); } fn main() { let p1 = Pair { a: 3, b: 9 }; let p2 = Pair { a: true, b: false }; print_type_name(&p1); // prints "Pair<i32>" print_type_name(&p2); // prints "Pair<bool...
fn print_type_of<T>(_:T) { println!("{}", unsafe { std::intrinsics::type_name::<T>() }); } fn main() { print_type_of(32.90); // prints "f64" print_type_of(vec![1, 2, 4]); // prints "std::vec::Vec<i32>" print_type_of("foo"); // prints "&str" } 需要切...
[feature(core_intrinsics)]fnmain(){letx=&false;print_type_name_of(x);let&x=&false;print_type_name_of(x);letrefx=&false;print_type_name_of(x);}fnprint_type_name_of<T>(_:T){println!("{}",unsafe{std::intrinsics::type_name::<T>()})} &boolbool&&bool 例子: #![feature(core_...
fnprint_type_of<T>(_:&T){ println!("{}",std::any::type_name::<T>()) } fnmain(){ letx:u32=1; print_type_of(&x); } 代码在这里--> https://gitee.com/neilengineer/learning-rust/blob/master/4-rust-basics/print_data_type/src/main.rs...
{std::intrinsics::type_name::<T>()});}fnmain(){println!("Hello, world!");letlogical:bool=true;print_type_of(logical);letmutinferred_type=12;print_type_of(inferred_type);inferred_type=4294967296i64;print_type_of(inferred_type);lett="a";print_type_of(t);letc='a';print_type_of(...
println!("{}", std::intrinsics::type_name::<T>() ); } fn main() { print_type_of(3); // prints "i32" print_type_of(32.90); // prints "f64" print_type_of(vec![102, 111, 111]); // prints "alloc::vec::Vec<i32>" ...
[feature(core_intrinsics)]fnmain(){letx=&false;print_type_name_of(x);let&y=&false;print_type_name_of(y);letrefz=&false;print_type_name_of(z);}fnprint_type_name_of<T>(_:T){println!("{}",unsafe{std::intrinsics::type_name::<T>()})}...
可以使用type_name方法获取一个类型的名称: usestd::any::Any;usestd::any::TypeId;fnmain() {leta =1;letb ="hello";letc =true;println!("a's type name: {:?}", std::any::type_name::<i32>());println!("b's type name: {:?}", std::any::type_name::< &str>());println!(...
可以试试std::any::type_name。注意,这个是unstable的。use std::co rust 参考文献 html 翻译 寻找繁星 2022-10-14 15:11:49 960阅读 python如何输出变量类型python输出变量类型 学习了下python的输入输出数据类型和变量。一、输入输出两个函数:print和inputprint用于输出,参数之间的逗号输出用空格隔开input用于输入...