File tree Expand file tree Collapse file tree 3 files changed +32
-9
lines changed Expand file tree Collapse file tree 3 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -102,10 +102,13 @@ fn main() {
102
102
let stderr = io:: stderr ( ) ;
103
103
let mut stderr = stderr. lock ( ) ;
104
104
105
- let options = DemangleOptions {
106
- no_params : matches. is_present ( "noparams" ) ,
107
- no_return_type : matches. is_present ( "noreturntype" ) ,
108
- } ;
105
+ let mut options = DemangleOptions :: new ( ) ;
106
+ if matches. is_present ( "noparams" ) {
107
+ options = options. no_params ( ) ;
108
+ }
109
+ if matches. is_present ( "noreturntype" ) {
110
+ options = options. no_return_type ( ) ;
111
+ }
109
112
110
113
let demangle_result = if let Some ( names) = matches. values_of ( "mangled_names" ) {
111
114
let mut input = Cursor :: new ( names. fold ( String :: new ( ) , |mut accumulated, name| {
Original file line number Diff line number Diff line change @@ -86,10 +86,27 @@ use std::fmt;
86
86
/// Options to control the demangling process.
87
87
#[ derive( Clone , Copy , Debug , Default ) ]
88
88
pub struct DemangleOptions {
89
+ no_params : bool ,
90
+ no_return_type : bool ,
91
+ }
92
+
93
+ impl DemangleOptions {
94
+ /// Construct a new `DemangleOptions` with the default values.
95
+ pub fn new ( ) -> Self {
96
+ Default :: default ( )
97
+ }
98
+
89
99
/// Do not display function arguments.
90
- pub no_params : bool ,
100
+ pub fn no_params ( mut self ) -> Self {
101
+ self . no_params = true ;
102
+ self
103
+ }
104
+
91
105
/// Do not display the function return type.
92
- pub no_return_type : bool ,
106
+ pub fn no_return_type ( mut self ) -> Self {
107
+ self . no_return_type = true ;
108
+ self
109
+ }
93
110
}
94
111
95
112
/// A `Symbol` which owns the underlying storage for the mangled name.
@@ -251,6 +268,9 @@ pub enum DemangleNodeType {
251
268
NestedName ,
252
269
/// Entering a <special-name> production that is a vtable.
253
270
VirtualTable ,
271
+ /// Additional values may be added in the future. Use a
272
+ /// _ pattern for compatibility.
273
+ __NonExhaustive,
254
274
}
255
275
256
276
/// Sink for demangled text that reports syntactic structure.
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ macro_rules! demangles_no_param_and_no_return_type {
87
87
( $name: ident , $mangled: expr , $demangled: expr ) => {
88
88
#[ test]
89
89
fn $name( ) {
90
- let options = DemangleOptions { no_params : true , no_return_type : true } ;
90
+ let options = DemangleOptions :: new ( ) . no_params ( ) . no_return_type ( ) ;
91
91
assert_demangles_as( $mangled, $demangled, Some ( options) ) ;
92
92
}
93
93
} ;
@@ -100,7 +100,7 @@ macro_rules! demangles_no_return_type {
100
100
( $name: ident , $mangled: expr , $demangled: expr ) => {
101
101
#[ test]
102
102
fn $name( ) {
103
- let options = DemangleOptions { no_params : false , no_return_type : true } ;
103
+ let options = DemangleOptions :: new ( ) . no_return_type ( ) ;
104
104
assert_demangles_as( $mangled, $demangled, Some ( options) ) ;
105
105
}
106
106
} ;
@@ -113,7 +113,7 @@ macro_rules! demangles_no_param {
113
113
( $name: ident , $mangled: expr , $demangled: expr ) => {
114
114
#[ test]
115
115
fn $name( ) {
116
- let options = DemangleOptions { no_params : true , no_return_type : false } ;
116
+ let options = DemangleOptions :: new ( ) . no_params ( ) ;
117
117
assert_demangles_as( $mangled, $demangled, Some ( options) ) ;
118
118
}
119
119
} ;
You can’t perform that action at this time.
0 commit comments