@@ -165,13 +165,12 @@ impl GeneratorVisitor<'_> for RustNativeBindingWriter<'_> {
165
165
fn visit_class ( & mut self , class : Class ) {
166
166
self . emit_debug_log ( & class) ;
167
167
if class. kind ( ) . is_trait ( ) {
168
- self . prelude_traits . push ( format ! (
169
- "super::{}" ,
170
- class. rust_trait_name( NameStyle :: decl( ) , Constness :: Const )
171
- ) ) ;
172
168
self
173
169
. prelude_traits
174
- . push ( format ! ( "super::{}" , class. rust_trait_name( NameStyle :: decl( ) , Constness :: Mut ) ) ) ;
170
+ . push ( class. rust_trait_name ( NameStyle :: decl ( ) , Constness :: Const ) . into_owned ( ) ) ;
171
+ self
172
+ . prelude_traits
173
+ . push ( class. rust_trait_name ( NameStyle :: decl ( ) , Constness :: Mut ) . into_owned ( ) ) ;
175
174
}
176
175
let name = class. cpp_name ( CppNameStyle :: Reference ) . into_owned ( ) ;
177
176
self . rust_classes . push ( ( name. clone ( ) , class. gen_rust ( self . opencv_version ) ) ) ;
@@ -216,7 +215,7 @@ impl GeneratorVisitor<'_> for RustNativeBindingWriter<'_> {
216
215
write_generated_type ( & self . types_dir , "cpp" , prio, & safe_id, || typ. gen_cpp ( ) ) ;
217
216
}
218
217
219
- fn goodbye ( self ) {
218
+ fn goodbye ( mut self ) {
220
219
static RUST : Lazy < CompiledInterpolation > = Lazy :: new ( || include_str ! ( "tpl/module/rust.tpl.rs" ) . compile_interpolation ( ) ) ;
221
220
222
221
static RUST_PRELUDE : Lazy < CompiledInterpolation > =
@@ -230,7 +229,13 @@ impl GeneratorVisitor<'_> for RustNativeBindingWriter<'_> {
230
229
insert_lines ( & mut rust, self . rust_typedefs . into_iter ( ) . collect ( ) ) ;
231
230
insert_lines ( & mut rust, self . rust_funcs ) ;
232
231
insert_lines ( & mut rust, self . rust_classes ) ;
233
- let prelude = RUST_PRELUDE . interpolate ( & HashMap :: from ( [ ( "traits" , self . prelude_traits . join ( ", " ) ) ] ) ) ;
232
+ let pub_use_traits = if self . prelude_traits . is_empty ( ) {
233
+ "" . to_string ( )
234
+ } else {
235
+ self . prelude_traits . sort_unstable ( ) ;
236
+ format ! ( "pub use super::{{{}}};" , self . prelude_traits. join( ", " ) )
237
+ } ;
238
+ let prelude = RUST_PRELUDE . interpolate ( & HashMap :: from ( [ ( "pub_use_traits" , pub_use_traits) ] ) ) ;
234
239
let comment = RenderComment :: new ( & self . comment , self . opencv_version ) ;
235
240
let comment = comment. render_with_comment_marker ( "//!" ) ;
236
241
File :: create ( & self . rust_path )
0 commit comments