@@ -122,14 +122,22 @@ where
122122 ""
123123 } ;
124124
125- let leading_comment = f. leading_comments . to_string ( ) ;
126- let trailing_comment = f. trailing_comments . to_string ( ) ;
125+ if self . config . with_comments {
126+ let leading_comment = f. leading_comments . to_string ( ) ;
127+ let trailing_comment = f. trailing_comments . to_string ( ) ;
127128
128- format ! {
129- r#"
129+ format ! {
130+ r#"
130131 {leading_comment}
131132 {attrs}
132133 {deprecated_attr}pub {name}: {ty},{trailing_comment}"#
134+ }
135+ } else {
136+ format ! {
137+ r#"
138+ {attrs}
139+ {deprecated_attr}pub {name}: {ty},"#
140+ }
133141 }
134142 } )
135143 } )
@@ -151,7 +159,11 @@ where
151159 ""
152160 } ;
153161
154- let trailing_comment = s. trailing_comments . to_string ( ) ;
162+ let trailing_comment = if self . config . with_comments {
163+ s. trailing_comments . as_str ( )
164+ } else {
165+ ""
166+ } ;
155167
156168 stream. push_str ( & format ! {
157169 r#"#[derive(Clone, PartialEq)]
@@ -177,14 +189,19 @@ where
177189 tracing:: trace!( "write item {}" , item. symbol_name( ) ) ;
178190
179191 // write leading comments
180- let comments = match & * item {
181- middle:: rir:: Item :: Message ( s) => s. leading_comments . to_string ( ) ,
182- middle:: rir:: Item :: Enum ( e) => e. leading_comments . to_string ( ) ,
183- middle:: rir:: Item :: Service ( s) => s. leading_comments . to_string ( ) ,
184- middle:: rir:: Item :: NewType ( t) => t. leading_comments . to_string ( ) ,
185- middle:: rir:: Item :: Const ( c) => c. leading_comments . to_string ( ) ,
186- _ => String :: new ( ) ,
192+ let comments = if self . config . with_comments {
193+ match & * item {
194+ middle:: rir:: Item :: Message ( s) => s. leading_comments . as_str ( ) ,
195+ middle:: rir:: Item :: Enum ( e) => e. leading_comments . as_str ( ) ,
196+ middle:: rir:: Item :: Service ( s) => s. leading_comments . as_str ( ) ,
197+ middle:: rir:: Item :: NewType ( t) => t. leading_comments . as_str ( ) ,
198+ middle:: rir:: Item :: Const ( c) => c. leading_comments . as_str ( ) ,
199+ _ => "" ,
200+ }
201+ } else {
202+ ""
187203 } ;
204+
188205 if !comments. is_empty ( ) {
189206 stream. push_str ( & format ! ( "\n {comments}\n " ) ) ;
190207 }
@@ -404,7 +421,11 @@ where
404421 format ! ( "({fields})" )
405422 } ;
406423
407- let leading_comment = v. leading_comments . to_string ( ) ;
424+ let leading_comment = if self . config . with_comments {
425+ v. leading_comments . as_str ( )
426+ } else {
427+ ""
428+ } ;
408429
409430 format ! (
410431 r#"{leading_comment}
@@ -418,7 +439,11 @@ where
418439 if self . cache . keep_unknown_fields . contains ( & def_id) && keep {
419440 variants. push_str ( "_UnknownFields(::pilota::BytesVec)," ) ;
420441 }
421- let trailing_comment = e. trailing_comments . to_string ( ) ;
442+ let trailing_comment = if self . config . with_comments {
443+ e. trailing_comments . as_str ( )
444+ } else {
445+ ""
446+ } ;
422447 stream. push_str ( & format ! {
423448 r#"
424449 #[derive(Clone, PartialEq)]
@@ -625,7 +650,7 @@ where
625650 for file_id in mod_files. get ( mod_path) . unwrap ( ) . iter ( ) {
626651 let file = this. file ( * file_id) . unwrap ( ) ;
627652 // 2.1.1 comments
628- if !file. comments . is_empty ( ) {
653+ if !file. comments . is_empty ( ) && this . config . with_comments {
629654 stream. push_str ( & format ! ( "\n {}\n " , file. comments) ) ;
630655 }
631656
0 commit comments