#demangle #name #symbol #structured #path #produces #mangled

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

#295 in Programming languages

Download history 57/week @ 2024-07-24 10/week @ 2024-07-31 4/week @ 2024-08-07 17/week @ 2024-08-14 20/week @ 2024-08-21 43/week @ 2024-08-28 18/week @ 2024-09-04 263/week @ 2024-09-11 292/week @ 2024-09-18 268/week @ 2024-09-25 129/week @ 2024-10-02 46/week @ 2024-10-09 46/week @ 2024-10-16 63/week @ 2024-10-23 58/week @ 2024-10-30 28/week @ 2024-11-06

204 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

~165KB