Extract the originating crate name from a demangled Rust symbol. Demangled symbols look like: uv_pep508::marker::simplify::collect_dnf core::num::flt2dec::strategy::dragon::format_shortest as core::fmt::Display>::fmt .rodata.core::num::dec2flt:
(symbol)
| 353 | |
| 354 | |
| 355 | def crate_from_symbol(symbol): |
| 356 | """Extract the originating crate name from a demangled Rust symbol. |
| 357 | |
| 358 | Demangled symbols look like: |
| 359 | uv_pep508::marker::simplify::collect_dnf |
| 360 | core::num::flt2dec::strategy::dragon::format_shortest |
| 361 | <uv_pep508::Requirement<T> as core::fmt::Display>::fmt |
| 362 | .rodata.core::num::dec2flt::table::POWER_OF_FIVE_128 |
| 363 | .rodata..Lanon.f2a1a4d36baa2f0507e070ce676efac8.547 |
| 364 | """ |
| 365 | # Strip .rodata. prefix from data segment symbols |
| 366 | s = re.sub(r"^\.rodata\.", "", symbol) |
| 367 | # Skip anonymous data segments — no crate info available |
| 368 | if s.startswith(".Lanon.") or s.startswith("anon."): |
| 369 | return None |
| 370 | s = s.lstrip("<") |
| 371 | m = re.match(r"([a-zA-Z_][a-zA-Z0-9_]*)::", s) |
| 372 | if m: |
| 373 | return m.group(1) |
| 374 | return None |
| 375 | |
| 376 | |
| 377 | # --------------------------------------------------------------------------- |
no test coverage detected