From 94459fbedf9cc63db727843f299d9da34fdda85b Mon Sep 17 00:00:00 2001 From: John Schock Date: Fri, 17 Nov 2023 12:06:51 -0800 Subject: [PATCH] Add function!() macro that yields current function name --- .../Crates/RustAdvancedLoggerDxe/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs b/AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs index 46db4f87e0..dd8eb18d8f 100644 --- a/AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs +++ b/AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs @@ -195,6 +195,19 @@ macro_rules! debugln { ($level:expr, $fmt:expr, $($arg:tt)*) => ($crate::debug!($level, concat!($fmt, "\n"), $($arg)*)); } +/// Yields a &'static str that is the name of the containing function. +#[macro_export] +macro_rules! function { + () => {{ + fn f() {} + fn type_name_of(_: T) -> &'static str { + core::any::type_name::() + } + let name = type_name_of(f); + name.strip_suffix("::f").unwrap() + }}; +} + #[cfg(test)] mod tests { extern crate std;