Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Created July 16, 2015 17:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benaryorg/dffabeb387009036a3eb to your computer and use it in GitHub Desktop.
Save benaryorg/dffabeb387009036a3eb to your computer and use it in GitHub Desktop.
get the name of the struct of a variable
#![feature(core_intrinsics)]
struct Something
{
data:u32,
}
impl Something
{
pub fn name(&self)->String
{
unsafe
{
(*std::intrinsics::type_name::<Self>()).to_string()
}
}
}
fn main()
{
let something=Something{data:0};
println!("{}",something.name());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment