Rust 打印变量类型
Rust 大约 269 字方法一
直接打印
fn print_type_of<T>(_: T) {
println!("type is {}", std::any::type_name::<T>())
}
方法二
返回全生命周期的字面量引用。
type_name
源码就是返回的&'static str
。
fn type_of<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
备注
Rust 1.38
中添加该特性。
阅读 137 · 发布于 2023-04-21
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称: