cpp_demangle

Type Alias OwnedSymbol

Source
pub type OwnedSymbol = Symbol<Vec<u8>>;
Expand description

A Symbol which owns the underlying storage for the mangled name.

Aliased Type§

struct OwnedSymbol { /* private fields */ }

Implementations

Source§

impl<T> Symbol<T>
where T: AsRef<[u8]>,

Source

pub fn new(raw: T) -> Result<Symbol<T>>

Given some raw storage, parse the mangled symbol from it with the default options.

use cpp_demangle::Symbol;
use std::string::ToString;

// First, something easy :)

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

// Now let's try something a little more complicated!

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>)"
);
Source

pub fn new_with_options(raw: T, options: &ParseOptions) -> Result<Symbol<T>>

Given some raw storage, parse the mangled symbol from it.

use cpp_demangle::{ParseOptions, Symbol};
use std::string::ToString;

// First, something easy :)

let mangled = b"_ZN5space3fooEibc";

let parse_options = ParseOptions::default()
    .recursion_limit(1024);

let sym = Symbol::new_with_options(&mangled[..], &parse_options)
    .expect("Could not parse mangled symbol!");

let demangled = sym.to_string();
assert_eq!(demangled, "space::foo(int, bool, char)");

// Now let's try something a little more complicated!

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>)"
);
Source

pub fn demangle(&self, options: &DemangleOptions) -> Result<String, Error>

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);
Source

pub fn structured_demangle<W: DemangleWrite>( &self, out: &mut W, options: &DemangleOptions, ) -> Result

Demangle the symbol to a DemangleWrite, which lets the consumer be informed about syntactic structure.

Trait Implementations

Source§

impl<T: Clone> Clone for Symbol<T>

Source§

fn clone(&self) -> Symbol<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Symbol<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for Symbol<T>
where T: AsRef<[u8]>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for Symbol<T>

Source§

fn eq(&self, other: &Symbol<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for Symbol<T>