Skip to content

Instantly share code, notes, and snippets.

@Jacobboogiebear
Created December 23, 2022 17:49
Show Gist options
  • Save Jacobboogiebear/ee54b8d64d262a205aff86152d7e8017 to your computer and use it in GitHub Desktop.
Save Jacobboogiebear/ee54b8d64d262a205aff86152d7e8017 to your computer and use it in GitHub Desktop.
#[macro_export]
macro_rules! type_name_of {
( $e:expr $(,)? ) => ({
fn __helper__<T> (_: [&T; 0]) -> &'static str {
core::any::type_name::<T>()
}
let it = [];
#[allow(unreachable_code)] {
if false {
loop {}
(&mut { it })[0] = &$e
}
}
__helper__(it)
})
} pub use type_name_of;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment