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

ast-demangle

解析模糊化名称并生成结构化结果

8个版本

0.3.1 2022年10月23日
0.3.0 2022年7月24日
0.2.3 2021年11月20日
0.1.1 2021年5月21日

235编程语言 中排名

Download history 11/week @ 2024-03-13 3/week @ 2024-03-20 15/week @ 2024-03-27 3/week @ 2024-04-03 6/week @ 2024-04-10 57/week @ 2024-04-17 10/week @ 2024-04-24 12/week @ 2024-05-01 1/week @ 2024-05-08 21/week @ 2024-06-05 87/week @ 2024-06-12 81/week @ 2024-06-19 143/week @ 2024-06-26

每月 332 次下载

MIT 许可证

120KB
3K SLoC

ast-demangle

crates.io docs CI Codecov Coveralls

解析模糊化名称并生成结构化结果。

示例

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"),
    }
);

依赖项

~165KB