ast-demangle

Crates.ioast-demangle
lib.rsast-demangle
version0.3.1
sourcesrc
created_at2021-05-15 07:18:17.597947
updated_at2022-10-23 05:43:19.79085
descriptionParses mangled names and produces structured results.
homepage
repositoryhttps://github.com/EFanZh/ast-demangle
max_upload_size
id397730
size284,668
EFanZh (EFanZh)

documentation

README

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"),
    }
);
Commit count: 74

cargo fmt