Struct cpp_demangle::Symbol[][src]

pub struct Symbol<T> { /* fields omitted */ }
Expand description

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.

Implementations

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

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

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

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

Parse a mangled symbol from input and return it and the trailing tail of bytes that come after the symbol, with the default options.

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

Parse a mangled symbol from input and return it and the trailing tail of bytes that come after the symbol.

While Symbol::new_with_options will return an error if there is unexpected trailing bytes, with_tail_and_options simply returns the trailing bytes along with the parsed symbol.

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

let mangled = b"_ZN5space3fooEibc and some trailing junk";

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

let (sym, tail) = BorrowedSymbol::with_tail_and_options(&mangled[..], &parse_options)
    .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)");

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. 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 !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.