@@ -167,31 +167,42 @@ impl<'tu> GeneratorVisitor<'tu> for RustNativeBindingWriter<'_> {
167
167
fn visit_dependent_type ( & mut self , typ : Self :: D ) {
168
168
let prio = typ. element_order ( ) ;
169
169
let safe_id = typ. element_safe_id ( ) ;
170
- let rust_path = self . types_dir . join ( format ! ( "{:03}-{}.type.rs" , prio , safe_id ) ) ;
171
- let cpp_path = self . types_dir . join ( format ! ( "{:03}-{}.type.cpp" , prio , safe_id ) ) ;
172
- let files = if self . debug {
173
- (
174
- OpenOptions :: new ( ) . create ( true ) . write ( true ) . truncate ( true ) . open ( & rust_path ) ,
175
- OpenOptions :: new ( ) . create ( true ) . write ( true ) . truncate ( true ) . open ( & cpp_path ) ,
176
- )
177
- } else {
178
- (
179
- OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . open ( & rust_path ) ,
180
- OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . open ( & cpp_path ) ,
181
- )
182
- } ;
183
- match files {
184
- ( Ok ( mut rust ) , Ok ( mut cpp ) ) => {
185
- rust . write_all ( typ . gen_rust ( self . opencv_version ) . as_bytes ( ) ) . expect ( "Can't write to rust file" ) ;
186
- cpp . write_all ( typ . gen_cpp ( ) . as_bytes ( ) ) . expect ( "Can't write to cpp file" ) ;
170
+
171
+ let mut gen = typ . gen_rust ( self . opencv_version ) ;
172
+ if !gen . is_empty ( ) {
173
+ let path = self . types_dir . join ( format ! ( "{:03}-{}.type.rs" , prio , safe_id ) ) ;
174
+ let file = if self . debug {
175
+ OpenOptions :: new ( ) . create ( true ) . write ( true ) . truncate ( true ) . open ( & path )
176
+ } else {
177
+ OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . open ( & path )
178
+ } ;
179
+ match file {
180
+ Ok ( mut file ) => {
181
+ file . write_all ( gen . as_bytes ( ) ) . expect ( "Can't write to rust file" ) ;
182
+ } ,
183
+ Err ( e ) if e . kind ( ) == ErrorKind :: AlreadyExists => { /* expected, we need to exclusively create file */ } ,
184
+ Err ( e ) => {
185
+ panic ! ( "Error while creating file for rust dependent type: {}" , e )
186
+ } ,
187
187
}
188
- ( Err ( e) , _) | ( _, Err ( e) ) => {
189
- match e. kind ( ) {
190
- ErrorKind :: AlreadyExists => { } // expected, we need to exclusively create file
191
- _ => {
192
- panic ! ( "Error while creating file for dependent type: {}" , e)
193
- }
194
- }
188
+ }
189
+
190
+ gen = typ. gen_cpp ( ) ;
191
+ if !gen. is_empty ( ) {
192
+ let path = self . types_dir . join ( format ! ( "{:03}-{}.type.cpp" , prio, safe_id) ) ;
193
+ let file = if self . debug {
194
+ OpenOptions :: new ( ) . create ( true ) . write ( true ) . truncate ( true ) . open ( & path)
195
+ } else {
196
+ OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . open ( & path)
197
+ } ;
198
+ match file {
199
+ Ok ( mut file) => {
200
+ file. write_all ( gen. as_bytes ( ) ) . expect ( "Can't write to cpp file" ) ;
201
+ } ,
202
+ Err ( e) if e. kind ( ) == ErrorKind :: AlreadyExists => { /* expected, we need to exclusively create file */ } ,
203
+ Err ( e) =>{
204
+ panic ! ( "Error while creating file for cpp dependent type: {}" , e)
205
+ } ,
195
206
}
196
207
}
197
208
}
0 commit comments