如何在Rust中打印变量的类型?
#![feature(core_intrinsics)] 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" }
需要切换rustup到nightly版本才能运行cargo run
查看rustup版本
rustup toolchain list
切换到nightly版本
rustup default nightly
相关推荐
归去来兮 2020-09-18
zhangxiafll 2020-11-13
svap 2020-11-09
viplinux 2020-10-28
Justhavefun 2020-10-22
lousir 2020-10-21
longzhiwen 2020-10-16
Justhavefun 2020-09-25
zhouxiaojie 2020-09-16
gamedevd 2020-09-04
tkernel 2020-09-03
Trustport 2020-09-01
svap 2020-08-25
tkernel 2020-08-18
lihn 2020-08-18
归去来兮 2020-07-28
TianlangStudio 2020-07-18
iammjun 2020-07-07
Colourful 2020-07-03