Skip to content

Instantly share code, notes, and snippets.

@xolve
Created May 9, 2019 10:58
Show Gist options
  • Save xolve/08d054f834475d22b92e631ac9c0beaa to your computer and use it in GitHub Desktop.
Save xolve/08d054f834475d22b92e631ac9c0beaa to your computer and use it in GitHub Desktop.
Rust print typenames - nightly only
#![feature(core_intrinsics)]
fn main() {
let x = &false;
print_type_name_of(x);
let ref x = false;
print_type_name_of(x);
let &x = &false;
print_type_name_of(x);
let ref x = &false;
print_type_name_of(x);
let z = 1;
let x = &z;
print_type_name_of(x);
let z = String::from("Hello");
let &x = &z;
let y = z;
print_type_name_of(x);
print_type_name_of(y);
}
fn print_type_name_of<T>(_: T) {
println!("{}", unsafe { std::intrinsics::type_name::<T>() })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment