]> git.lizzy.rs Git - rust.git/commitdiff
add example for type_name
authorLzu Tao <taolzu@gmail.com>
Wed, 16 Oct 2019 16:50:07 +0000 (16:50 +0000)
committerLzu Tao <taolzu@gmail.com>
Wed, 16 Oct 2019 16:54:04 +0000 (16:54 +0000)
src/libcore/any.rs

index f75b7a454438406c25bbf0025fc26ac6e8644367..e2704e807d104bd42378db2b496e5d5abf1fdd7a 100644 (file)
@@ -445,6 +445,15 @@ pub const fn of<T: ?Sized + 'static>() -> TypeId {
 ///
 /// The current implementation uses the same infrastructure as compiler
 /// diagnostics and debuginfo, but this is not guaranteed.
+///
+/// # Example
+///
+/// ```rust
+/// assert_eq!(
+///     std::any::type_name::<Option<String>>(),
+///     "core::option::Option<alloc::string::String>",
+/// );
+/// ```
 #[stable(feature = "type_name", since = "1.38.0")]
 #[rustc_const_unstable(feature = "const_type_name")]
 pub const fn type_name<T: ?Sized>() -> &'static str {