#demangle #mangled #name #path #identifier #symbol #results

ast-demangle

Parses mangled names and produces structured results

8 releases

0.3.1 Oct 23, 2022
0.3.0 Jul 24, 2022
0.2.3 Nov 20, 2021
0.1.1 May 21, 2021

#210 in Programming languages

28 downloads per month

MIT license

120KB
3K SLoC

ast-demangle

crates.io docs CI Codecov Coveralls

Parses mangled names and produces structured results.

Example:

use ast_demangle::rust_v0::{DisplayStyle, Identifier, Path, Symbol};
use std::borrow::Cow;

let mangled_name = "_RNvNtCs6GSVXm7oiwY_5regex4utf811decode_utf8.llvm.1119170478327948870";
let (symbol, suffix) = Symbol::parse_from_str(mangled_name).unwrap();

// The suffix is returned.
assert_eq!(suffix, "");

// The default style for displaying is the long format.
assert_eq!(format!("{}", symbol), "regex[4df147058689a776]::utf8::decode_utf8");

// To omit the crate hash, use the alternate display format.
assert_eq!(format!("{:#}", symbol), "regex::utf8::decode_utf8");

// Use `Symbol::display` and `DisplayStyle` to specify the display style explicitly.

assert_eq!(format!("{}", symbol.display(DisplayStyle::Short)), "decode_utf8");
assert_eq!(format!("{}", symbol.display(DisplayStyle::Normal)), "regex::utf8::decode_utf8");

assert_eq!(
    format!("{}", symbol.display(DisplayStyle::Long)),
    "regex[4df147058689a776]::utf8::decode_utf8"
);

// You can access the structure of the demangled symbol.

assert_eq!(
    symbol,
    Symbol {
        version: None,
        path: Path::Nested {
            namespace: b'v',
            path: Path::Nested {
                namespace: b't',
                path: Path::CrateRoot(Identifier {
                    disambiguator: 0x4df1_4705_8689_a776,
                    name: Cow::Borrowed("regex")
                })
                .into(),
                identifier: Identifier {
                    disambiguator: 0,
                    name: Cow::Borrowed("utf8")
                }
            }
            .into(),
            identifier: Identifier {
                disambiguator: 0,
                name: Cow::Borrowed("decode_utf8")
            }
        }
        .into(),
        instantiating_crate: None,
        vendor_specific_suffix: Some(".llvm.1119170478327948870"),
    }
);

Dependencies

~170KB