Skip to content

Commit

Permalink
Add function!() macro that yields current function name
Browse files Browse the repository at this point in the history
  • Loading branch information
joschock authored and kenlautner committed Dec 20, 2023
1 parent 132d358 commit 0c369c2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(_: T) -> &'static str {
core::any::type_name::<T>()
}
let name = type_name_of(f);
name.strip_suffix("::f").unwrap()
}};
}

#[cfg(test)]
mod tests {
extern crate std;
Expand Down

0 comments on commit 0c369c2

Please sign in to comment.