Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
:timing
:sccache 1Tips & Traps¶
std::any::type_name::<i32>()"i32"std::any::type_name::<0>()std::any::type_name::<0>()
^
constant provided when a type was expecteduse std::any::{Any, TypeId};std::TypeId::of::<i32>()
consider importing one of these items#![feature(type_name_of_val)]
use std::any::type_name_of_val;
let x = 1;
println!("{}", type_name_of_val(&x));
let y = 1.0;
println!("{}", type_name_of_val(&y));#![feature(type_name_of_val)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
an inner attribute is not permitted in this context
use of unstable library feature 'type_name_of_val'println!("{}", type_name_of_val(&x));
^^^^^^^^^^^^^^^^
use of unstable library feature 'type_name_of_val'println!("{}", type_name_of_val(&y));
^^^^^^^^^^^^^^^^
use of unstable library feature 'type_name_of_val'align_of,
align_of_val and
size_of and size_of_val
fn print_type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>());
}
fn main() {
let x: &str = "abc";
print_type_of(&x); // prints "f64"
print_type_of(&vec![1, 2, 4]); // prints "std::vec::Vec<i32>"
print_type_of(&"foo"); // prints "&str"
}:dep typename = "0.1.2"use typename::TypeName;String::type_name()"std::string::String"Vec::<i32>::type_name()"std::vec::Vec<i32>"[0, 1, 2].type_name_of()"[i32; 3]"