@@ -1101,7 +1101,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
1101
1101
} ,
1102
1102
( "Sync" , _, _) => { } , ( "Send" , _, _) => { } ,
1103
1103
( "std::marker::Sync" , _, _) => { } , ( "std::marker::Send" , _, _) => { } ,
1104
- ( "core::fmt::Debug" , _, _) => { } ,
1104
+ ( "core::fmt::Debug" , _, _) => {
1105
+ writeln!( w, "\t \t debug_str: {}_debug_str_void," , ident) . unwrap( ) ;
1106
+ } ,
1105
1107
( s, t, _) => {
1106
1108
if let Some ( supertrait_obj) = types. crate_types. traits. get( s) {
1107
1109
macro_rules! write_impl_fields {
@@ -1298,8 +1300,8 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
1298
1300
write ! ( w, "#[must_use]\n #[no_mangle]\n pub extern \" C\" fn {}_default() -> {} {{\n " , ident, ident) . unwrap ( ) ;
1299
1301
write ! ( w, "\t {} {{ inner: ObjOps::heap_alloc(Default::default()), is_owned: true }}\n " , ident) . unwrap ( ) ;
1300
1302
write ! ( w, "}}\n " ) . unwrap ( ) ;
1301
- } else if path_matches_nongeneric ( & trait_path . 1 , & [ "core" , "cmp" , " PartialEq"] ) {
1302
- } else if path_matches_nongeneric ( & trait_path . 1 , & [ "core" , "cmp" , " Eq"] ) {
1303
+ } else if full_trait_path_opt . as_ref ( ) . map ( |s| s . as_str ( ) ) == Some ( "core::cmp:: PartialEq") {
1304
+ } else if full_trait_path_opt . as_ref ( ) . map ( |s| s . as_str ( ) ) == Some ( "core::cmp:: Eq") {
1303
1305
writeln ! ( w, "/// Checks if two {}s contain equal inner contents." , ident) . unwrap ( ) ;
1304
1306
writeln ! ( w, "/// This ignores pointers and is_owned flags and looks at the values in fields." ) . unwrap ( ) ;
1305
1307
if types. c_type_has_inner_from_path ( & resolved_path) {
@@ -1325,7 +1327,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
1325
1327
types. write_from_c_conversion_suffix ( w, & ref_type, Some ( & gen_types) ) ;
1326
1328
1327
1329
writeln ! ( w, " {{ true }} else {{ false }}\n }}" ) . unwrap ( ) ;
1328
- } else if path_matches_nongeneric ( & trait_path . 1 , & [ "core" , "hash" , " Hash"] ) {
1330
+ } else if full_trait_path_opt . as_ref ( ) . map ( |s| s . as_str ( ) ) == Some ( "core::hash:: Hash") {
1329
1331
writeln ! ( w, "/// Generates a non-cryptographic 64-bit hash of the {}." , ident) . unwrap ( ) ;
1330
1332
write ! ( w, "#[no_mangle]\n pub extern \" C\" fn {}_hash(o: &{}) -> u64 {{\n " , ident, ident) . unwrap ( ) ;
1331
1333
if types. c_type_has_inner_from_path ( & resolved_path) {
@@ -1345,8 +1347,8 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
1345
1347
types. write_from_c_conversion_suffix ( w, & ref_type, Some ( & gen_types) ) ;
1346
1348
writeln ! ( w, ", &mut hasher);" ) . unwrap ( ) ;
1347
1349
writeln ! ( w, "\t core::hash::Hasher::finish(&hasher)\n }}" ) . unwrap ( ) ;
1348
- } else if ( path_matches_nongeneric ( & trait_path . 1 , & [ "core" , "clone" , " Clone"] ) || path_matches_nongeneric ( & trait_path. 1 , & [ "Clone" ] ) ) &&
1349
- types. c_type_has_inner_from_path ( & resolved_path) {
1350
+ } else if ( full_trait_path_opt . as_ref ( ) . map ( |s| s . as_str ( ) ) == Some ( "core::clone:: Clone") || path_matches_nongeneric ( & trait_path. 1 , & [ "Clone" ] ) ) &&
1351
+ types. c_type_has_inner_from_path ( & resolved_path) {
1350
1352
writeln ! ( w, "impl Clone for {} {{" , ident) . unwrap ( ) ;
1351
1353
writeln ! ( w, "\t fn clone(&self) -> Self {{" ) . unwrap ( ) ;
1352
1354
writeln ! ( w, "\t \t Self {{" ) . unwrap ( ) ;
@@ -1399,6 +1401,12 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
1399
1401
1400
1402
writeln ! ( w, "\t }}.into()\n }}" ) . unwrap ( ) ;
1401
1403
}
1404
+ } else if full_trait_path_opt. as_ref ( ) . map ( |s| s. as_str ( ) ) == Some ( "core::fmt::Debug" ) {
1405
+ writeln ! ( w, "/// Get a string which allows debug introspection of a {} object" , ident) . unwrap ( ) ;
1406
+ writeln ! ( w, "pub extern \" C\" fn {}_debug_str_void(o: *const c_void) -> Str {{" , ident) . unwrap ( ) ;
1407
+
1408
+ write ! ( w, "\t alloc::format!(\" {{:?}}\" , unsafe {{ o as *const crate::{} }}).into()" , resolved_path) . unwrap ( ) ;
1409
+ writeln ! ( w, "}}" ) . unwrap ( ) ;
1402
1410
} else if path_matches_nongeneric ( & trait_path. 1 , & [ "Display" ] ) {
1403
1411
writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
1404
1412
writeln ! ( w, "/// Get the string representation of a {} object" , ident) . unwrap ( ) ;
@@ -1809,7 +1817,11 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
1809
1817
1810
1818
macro_rules! write_conv {
1811
1819
( $fn_sig: expr, $to_c: expr, $ref: expr) => {
1812
- writeln!( w, "\t #[allow(unused)]\n \t pub(crate) fn {} {{\n \t \t match {} {{" , $fn_sig, if $to_c { "native" } else { "self" } ) . unwrap( ) ;
1820
+ writeln!( w, "\t #[allow(unused)]\n \t pub(crate) fn {} {{" , $fn_sig) . unwrap( ) ;
1821
+ if $to_c && $ref {
1822
+ writeln!( w, "\t \t let native = unsafe {{ &*(native as *const _ as *const c_void as *const native{}) }};" , e. ident) . unwrap( ) ;
1823
+ }
1824
+ writeln!( w, "\t \t match {} {{" , if $to_c { "native" } else { "self" } ) . unwrap( ) ;
1813
1825
for var in e. variants. iter( ) {
1814
1826
write!( w, "\t \t \t {}{}::{} " , if $to_c { "native" } else { "" } , e. ident, var. ident) . unwrap( ) ;
1815
1827
let mut empty_tuple_variant = false ;
@@ -1933,7 +1945,10 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
1933
1945
}
1934
1946
write_conv ! ( format!( "into_native(self) -> native{}" , e. ident) , false , false ) ;
1935
1947
if is_clonable {
1936
- write_conv ! ( format!( "from_native(native: &native{}) -> Self" , e. ident) , true , true ) ;
1948
+ let mut args = Vec :: new ( ) ;
1949
+ maybe_write_non_lifetime_generics ( & mut args, & e. generics , & syn:: PathArguments :: None , & types) ;
1950
+ let fn_line = format ! ( "from_native(native: &{}Import{}) -> Self" , e. ident, String :: from_utf8( args) . unwrap( ) ) ;
1951
+ write_conv ! ( fn_line, true , true ) ;
1937
1952
}
1938
1953
write_conv ! ( format!( "native_into(native: native{}) -> Self" , e. ident) , true , false ) ;
1939
1954
writeln ! ( w, "}}" ) . unwrap ( ) ;
0 commit comments