pub struct Symbol<T> { /* fields omitted */ }
A mangled symbol that has been parsed into an AST.
This is generic over some storage type T
which can be either owned or
borrowed. See the OwnedSymbol
and BorrowedSymbol
type aliases.
Given some raw storage, parse the mangled symbol from it.
use cpp_demangle::Symbol;
use std::string::ToString;
let mangled = b"_ZN5space3fooEibc";
let sym = Symbol::new(&mangled[..])
.expect("Could not parse mangled symbol!");
let demangled = sym.to_string();
assert_eq!(demangled, "space::foo(int, bool, char)");
let mangled =
b"__Z28JS_GetPropertyDescriptorByIdP9JSContextN2JS6HandleIP8JSObjectEENS2_I4jsidEENS1_13MutableHandleINS1_18PropertyDescriptorEEE";
let sym = Symbol::new(&mangled[..])
.expect("Could not parse mangled symbol!");
let demangled = sym.to_string();
assert_eq!(
demangled,
"JS_GetPropertyDescriptorById(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::MutableHandle<JS::PropertyDescriptor>)"
);
Demangle the symbol and return it as a String.
Unlike the ToString
implementation, this function allows options to
be specified.
use cpp_demangle::{DemangleOptions, Symbol};
use std::string::ToString;
let mangled = b"_ZN5space3fooEibc";
let sym = Symbol::new(&mangled[..])
.expect("Could not parse mangled symbol!");
let demangled = sym.to_string();
let options = DemangleOptions::default();
let demangled_again = sym.demangle(&options).unwrap();
assert_eq!(demangled_again, demangled);
Parse a mangled symbol from input and return it and the trailing tail of
bytes that come after the symbol.
While Symbol::new
will return an error if there is unexpected trailing
bytes, with_tail
simply returns the trailing bytes along with the
parsed symbol.
use cpp_demangle::BorrowedSymbol;
use std::string::ToString;
let mangled = b"_ZN5space3fooEibc and some trailing junk";
let (sym, tail) = BorrowedSymbol::with_tail(&mangled[..])
.expect("Could not parse mangled symbol!");
assert_eq!(tail, b" and some trailing junk");
let demangled = sym.to_string();
assert_eq!(demangled, "space::foo(int, bool, char)");
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more