Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


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中添加该特性。

阅读 596 · 发布于 2023-04-21

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批