pub trait Demangle {
// Required methods
fn detect_language(&self) -> Language;
fn demangle(&self, opts: DemangleOptions) -> Option<String>;
fn try_demangle(&self, opts: DemangleOptions) -> Cow<'_, str>;
}
Expand description
An extension trait on Name
for demangling names.
See the module level documentation for a list of supported languages.
Required Methods§
Sourcefn detect_language(&self) -> Language
fn detect_language(&self) -> Language
Infers the language of a mangled name.
In case the symbol is not mangled or its language is unknown, the return value will be
Language::Unknown
. If the language of the symbol was specified explicitly, this is
returned instead. For a list of supported languages, see the module level documentation.
§Examples
use symbolic_common::{Language, Name};
use symbolic_demangle::{Demangle, DemangleOptions};
assert_eq!(Name::from("_ZN3foo3barEv").detect_language(), Language::Cpp);
assert_eq!(Name::from("unknown").detect_language(), Language::Unknown);
Sourcefn demangle(&self, opts: DemangleOptions) -> Option<String>
fn demangle(&self, opts: DemangleOptions) -> Option<String>
Demangles the name with the given options.
Returns None
in one of the following cases:
- The language cannot be detected.
- The language is not supported.
- Demangling of the name failed.
§Examples
use symbolic_common::Name;
use symbolic_demangle::{Demangle, DemangleOptions};
assert_eq!(
Name::from("_ZN3foo3barEv").demangle(DemangleOptions::name_only()),
Some("foo::bar".to_string())
);
assert_eq!(
Name::from("unknown").demangle(DemangleOptions::name_only()),
None
);
Sourcefn try_demangle(&self, opts: DemangleOptions) -> Cow<'_, str>
fn try_demangle(&self, opts: DemangleOptions) -> Cow<'_, str>
Tries to demangle the name and falls back to the original name.
Similar to demangle
, except that it returns a borrowed instance of the original name if
the name cannot be demangled.
§Examples
use symbolic_common::Name;
use symbolic_demangle::{Demangle, DemangleOptions};
assert_eq!(
Name::from("_ZN3foo3barEv").try_demangle(DemangleOptions::name_only()),
"foo::bar"
);
assert_eq!(
Name::from("unknown").try_demangle(DemangleOptions::name_only()),
"unknown"
);