@@ -1101,7 +1101,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
11011101 } ,
11021102 ( "Sync" , _, _) => { } , ( "Send" , _, _) => { } ,
11031103 ( "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+ } ,
11051107 ( s, t, _) => {
11061108 if let Some ( supertrait_obj) = types. crate_types. traits. get( s) {
11071109 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
12981300 write ! ( w, "#[must_use]\n #[no_mangle]\n pub extern \" C\" fn {}_default() -> {} {{\n " , ident, ident) . unwrap ( ) ;
12991301 write ! ( w, "\t {} {{ inner: ObjOps::heap_alloc(Default::default()), is_owned: true }}\n " , ident) . unwrap ( ) ;
13001302 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") {
13031305 writeln ! ( w, "/// Checks if two {}s contain equal inner contents." , ident) . unwrap ( ) ;
13041306 writeln ! ( w, "/// This ignores pointers and is_owned flags and looks at the values in fields." ) . unwrap ( ) ;
13051307 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
13251327 types. write_from_c_conversion_suffix ( w, & ref_type, Some ( & gen_types) ) ;
13261328
13271329 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") {
13291331 writeln ! ( w, "/// Generates a non-cryptographic 64-bit hash of the {}." , ident) . unwrap ( ) ;
13301332 write ! ( w, "#[no_mangle]\n pub extern \" C\" fn {}_hash(o: &{}) -> u64 {{\n " , ident, ident) . unwrap ( ) ;
13311333 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
13451347 types. write_from_c_conversion_suffix ( w, & ref_type, Some ( & gen_types) ) ;
13461348 writeln ! ( w, ", &mut hasher);" ) . unwrap ( ) ;
13471349 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) {
13501352 writeln ! ( w, "impl Clone for {} {{" , ident) . unwrap ( ) ;
13511353 writeln ! ( w, "\t fn clone(&self) -> Self {{" ) . unwrap ( ) ;
13521354 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
13991401
14001402 writeln ! ( w, "\t }}.into()\n }}" ) . unwrap ( ) ;
14011403 }
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 ( ) ;
14021410 } else if path_matches_nongeneric ( & trait_path. 1 , & [ "Display" ] ) {
14031411 writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
14041412 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
18091817
18101818 macro_rules! write_conv {
18111819 ( $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( ) ;
18131825 for var in e. variants. iter( ) {
18141826 write!( w, "\t \t \t {}{}::{} " , if $to_c { "native" } else { "" } , e. ident, var. ident) . unwrap( ) ;
18151827 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
19331945 }
19341946 write_conv ! ( format!( "into_native(self) -> native{}" , e. ident) , false , false ) ;
19351947 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 ) ;
19371952 }
19381953 write_conv ! ( format!( "native_into(native: native{}) -> Self" , e. ident) , true , false ) ;
19391954 writeln ! ( w, "}}" ) . unwrap ( ) ;
0 commit comments