Function std::any::type_name

1.38.0 (const: unstable) · source ·
pub fn type_name<T>() -> &'static str
where T: ?Sized,
Expand description

Returns the name of a type as a string slice.

Note

This is intended for diagnostic use. The exact contents and format of the string returned are not specified, other than being a best-effort description of the type. For example, amongst the strings that type_name::<Option<String>>() might return are "Option<String>" and "std::option::Option<std::string::String>".

The returned string must not be considered to be a unique identifier of a type as multiple types may map to the same type name. Similarly, there is no guarantee that all parts of a type will appear in the returned string: for example, lifetime specifiers are currently not included. In addition, the output may change between versions of the compiler.

The current implementation uses the same infrastructure as compiler diagnostics and debuginfo, but this is not guaranteed.

Examples

assert_eq!(
    std::any::type_name::<Option<String>>(),
    "core::option::Option<alloc::string::String>",
);
Run