Created
May 9, 2019 10:58
-
-
Save xolve/08d054f834475d22b92e631ac9c0beaa to your computer and use it in GitHub Desktop.
Rust print typenames - nightly only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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