Skip to main content

demangle_function_name

Function demangle_function_name 

Source
pub fn demangle_function_name(name: &str) -> String
Expand description

Demangle a Rust function name if it’s mangled.

This function handles both legacy and v0 mangling schemes:

  • Legacy: starts with _ZN
  • v0: starts with _RNv

If the name is not mangled (already human-readable), it returns the original name unchanged.

§Arguments

  • name - The potentially mangled function name

§Returns

The demangled function name, or the original if not mangled.

§Example

use debtmap::risk::lcov::demangle::demangle_function_name;

// Already demangled - returns as-is
let name = "my_module::my_function";
assert_eq!(demangle_function_name(name), name);

// Mangled name - returns demangled
let mangled = "_ZN3foo3barE";
let demangled = demangle_function_name(mangled);
assert!(!demangled.starts_with("_ZN"));

§Performance

O(n) where n is the length of the mangled name. Single pass through the string with minimal allocations.