11use std:: borrow:: Cow ;
2+ use std:: borrow:: Cow :: { Borrowed , Owned } ;
23use std:: collections:: HashMap ;
34use std:: sync:: LazyLock ;
45
@@ -40,13 +41,6 @@ impl RustElement for Const<'_> {
4041 } ,
4142 }
4243 }
43-
44- fn rendered_doc_comment ( & self , comment_marker : & str , opencv_version : & str ) -> String {
45- match self {
46- & Self :: Clang { entity } => DefaultRustNativeElement :: rendered_doc_comment ( entity, comment_marker, opencv_version) ,
47- Self :: Desc ( _) => "" . to_string ( ) ,
48- }
49- }
5044}
5145
5246impl RustNativeGeneratedElement for Const < ' _ > {
@@ -76,11 +70,11 @@ impl RustNativeGeneratedElement for Const<'_> {
7670 . unwrap_or ( & value. kind )
7771 . rust_type ( ) ;
7872 RUST_TPL . interpolate ( & HashMap :: from ( [
79- ( "doc_comment" , Cow :: Owned ( self . rendered_doc_comment ( "///" , opencv_version) ) ) ,
73+ ( "doc_comment" , Owned ( self . rust_doc_comment ( "///" , opencv_version) ) ) ,
8074 ( "debug" , self . get_debug ( ) . into ( ) ) ,
8175 ( "name" , name) ,
8276 ( "type" , typ. into ( ) ) ,
83- ( "value" , value. rust_render ( ) . into ( ) ) ,
77+ ( "value" , value. rust_render ( ) ) ,
8478 ] ) )
8579 } else {
8680 "" . to_string ( )
@@ -106,28 +100,28 @@ impl ValueKindExt for ValueKind {
106100}
107101
108102pub trait ValueExt {
109- fn rust_render ( self ) -> String ;
103+ fn rust_render ( & self ) -> Cow < ' _ , str > ;
110104}
111105
112106impl ValueExt for Value {
113- fn rust_render ( self ) -> String {
107+ fn rust_render ( & self ) -> Cow < ' _ , str > {
114108 match self . kind {
115- ValueKind :: Float | ValueKind :: Double if !self . value . contains ( '.' ) => {
116- format ! ( "{}." , self . value)
117- }
109+ ValueKind :: Float | ValueKind :: Double if !self . value . contains ( '.' ) => Owned ( format ! ( "{}." , self . value) ) ,
118110 ValueKind :: Integer => {
119111 if let Some ( no_prefix) = self . value . strip_prefix ( "0x" ) {
120112 // todo: use let chain when MSRV is 1.88
121113 if i32:: from_str_radix ( no_prefix, 16 ) . is_err ( ) {
122- format ! ( "{}u32 as i32" , self . value)
114+ Owned ( format ! ( "{}u32 as i32" , self . value) )
123115 } else {
124- self . value
116+ Borrowed ( & self . value )
125117 }
126118 } else {
127- self . value
119+ Borrowed ( & self . value )
128120 }
129121 }
130- ValueKind :: UnsignedInteger | ValueKind :: Usize | ValueKind :: Float | ValueKind :: Double | ValueKind :: String => self . value ,
122+ ValueKind :: UnsignedInteger | ValueKind :: Usize | ValueKind :: Float | ValueKind :: Double | ValueKind :: String => {
123+ Borrowed ( & self . value )
124+ }
131125 }
132126 }
133127}
0 commit comments