Skip to content

Commit 4f31c12

Browse files
committed
Add a standalone error type for try_demangle
1 parent 6dc0d20 commit 4f31c12

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ pub fn demangle(s: &str) -> Demangle {
127127
}
128128
}
129129

130+
/// Error returned from the `try_demangle` function below when demangling fails.
131+
#[derive(Debug, Clone)]
132+
pub struct TryDemangleError {
133+
_priv: (),
134+
}
135+
130136
/// The same as `demangle`, except return an `Err` if the string does not appear
131137
/// to be a Rust symbol, rather than "demangling" the given string as a no-op.
132138
///
@@ -141,12 +147,12 @@ pub fn demangle(s: &str) -> Demangle {
141147
/// // While `demangle` will just pass the non-symbol through as a no-op.
142148
/// assert_eq!(rustc_demangle::demangle(not_a_rust_symbol).as_str(), not_a_rust_symbol);
143149
/// ```
144-
pub fn try_demangle(s: &str) -> Result<Demangle, ()> {
150+
pub fn try_demangle(s: &str) -> Result<Demangle, TryDemangleError> {
145151
let sym = demangle(s);
146152
if sym.valid {
147153
Ok(sym)
148154
} else {
149-
Err(())
155+
Err(TryDemangleError { _priv: () })
150156
}
151157
}
152158

0 commit comments

Comments
 (0)