File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,29 @@ pub fn demangle(s: &str) -> Demangle {
127
127
}
128
128
}
129
129
130
+ /// The same as `demangle`, except return an `Err` if the string does not appear
131
+ /// to be a Rust symbol, rather than "demangling" the given string as a no-op.
132
+ ///
133
+ /// ```
134
+ /// extern crate rustc_demangle;
135
+ ///
136
+ /// let not_a_rust_symbol = "la la la";
137
+ ///
138
+ /// // The `try_demangle` function will reject strings which are not Rust symbols.
139
+ /// assert!(rustc_demangle::try_demangle(not_a_rust_symbol).is_err());
140
+ ///
141
+ /// // While `demangle` will just pass the non-symbol through as a no-op.
142
+ /// assert_eq!(rustc_demangle::demangle(not_a_rust_symbol).as_str(), not_a_rust_symbol);
143
+ /// ```
144
+ pub fn try_demangle ( s : & str ) -> Result < Demangle , ( ) > {
145
+ let sym = demangle ( s) ;
146
+ if sym. valid {
147
+ Ok ( sym)
148
+ } else {
149
+ Err ( ( ) )
150
+ }
151
+ }
152
+
130
153
impl < ' a > Demangle < ' a > {
131
154
/// Returns the underlying string that's being demangled.
132
155
pub fn as_str ( & self ) -> & ' a str {
You can’t perform that action at this time.
0 commit comments