Skip to content

Commit 82161f3

Browse files
committed
Add some examples
1 parent 8c0ebb6 commit 82161f3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
//! sentinel value that can be used to learn about the demangled version of a
55
//! symbol name. The demangled representation will be the same as the original
66
//! if it doesn't look like a mangled symbol name.
7+
//!
8+
//! # Examples
9+
//!
10+
//! ```
11+
//! use rustc_demangle::demangle;
12+
//!
13+
//! assert_eq!(demangle("_ZN4testE").to_string(), "test");
14+
//! assert_eq!(demangle("_ZN3foo3barE").to_string(), "foo::bar");
15+
//! assert_eq!(demangle("foo").to_string(), "foo");
16+
//! ```
717
818
#![no_std]
919
#![deny(missing_docs)]
@@ -32,6 +42,16 @@ pub struct Demangle<'a> {
3242
/// `Symbol` which is in turn resolved from a `Frame`) and then writes the
3343
/// de-mangled version into the given `writer`. If the symbol does not look like
3444
/// a mangled symbol, it is still written to `writer`.
45+
///
46+
/// # Examples
47+
///
48+
/// ```
49+
/// use rustc_demangle::demangle;
50+
///
51+
/// assert_eq!(demangle("_ZN4testE").to_string(), "test");
52+
/// assert_eq!(demangle("_ZN3foo3barE").to_string(), "foo::bar");
53+
/// assert_eq!(demangle("foo").to_string(), "foo");
54+
/// ```
3555
3656
// All rust symbols are in theory lists of "::"-separated identifiers. Some
3757
// assemblers, however, can't handle these characters in symbol names. To get
@@ -41,7 +61,7 @@ pub struct Demangle<'a> {
4161
// 2. For each element of the path, emit the length plus the element
4262
// 3. End the path with "E"
4363
//
44-
// For example, "_ZN4testE" => "test" and "_ZN3foo3bar" => "foo::bar".
64+
// For example, "_ZN4testE" => "test" and "_ZN3foo3barE" => "foo::bar".
4565
//
4666
// We're the ones printing our backtraces, so we can't rely on anything else to
4767
// demangle our symbols. It's *much* nicer to look at demangled symbols, so

0 commit comments

Comments
 (0)