Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.