@@ -681,7 +681,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
681
681
fn is_known_container ( & self , full_path : & str , is_ref : bool ) -> bool {
682
682
( full_path == "Result" && !is_ref) || ( full_path == "Vec" && !is_ref) || full_path. ends_with ( "Tuple" )
683
683
}
684
- fn to_c_conversion_container_new_var < ' b > ( & self , full_path : & str , is_ref : bool , single_contained : Option < & syn:: Type > , var_name : & syn:: Ident , var_access : & str )
684
+ fn to_c_conversion_container_new_var < ' b > ( & self , generics : Option < & GenericTypes > , full_path : & str , is_ref : bool , single_contained : Option < & syn:: Type > , var_name : & syn:: Ident , var_access : & str )
685
685
// Returns prefix + Vec<(prefix, var-name-to-inline-convert)> + suffix
686
686
// expecting one element in the vec per generic type, each of which is inline-converted
687
687
-> Option < ( & ' b str , Vec < ( String , String ) > , & ' b str ) > {
@@ -700,7 +700,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
700
700
} ,
701
701
"Option" => {
702
702
if let Some ( syn:: Type :: Path ( p) ) = single_contained {
703
- if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , None ) ) {
703
+ if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , generics ) ) {
704
704
if is_ref {
705
705
return Some ( ( "if " , vec ! [
706
706
( ".is_none() { std::ptr::null() } else { " . to_owned( ) , format!( "({}.as_ref().unwrap())" , var_access) )
@@ -714,7 +714,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
714
714
}
715
715
if let Some ( t) = single_contained {
716
716
let mut v = Vec :: new ( ) ;
717
- self . write_empty_rust_val ( & mut v, t) ;
717
+ self . write_empty_rust_val ( generics , & mut v, t) ;
718
718
let s = String :: from_utf8 ( v) . unwrap ( ) ;
719
719
return Some ( ( "if " , vec ! [
720
720
( format!( ".is_none() {{ {} }} else {{ " , s) , format!( "({}.unwrap())" , var_access) )
@@ -727,7 +727,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
727
727
728
728
/// only_contained_has_inner implies that there is only one contained element in the container
729
729
/// and it has an inner field (ie is an "opaque" type we've defined).
730
- fn from_c_conversion_container_new_var < ' b > ( & self , full_path : & str , is_ref : bool , single_contained : Option < & syn:: Type > , var_name : & syn:: Ident , var_access : & str )
730
+ fn from_c_conversion_container_new_var < ' b > ( & self , generics : Option < & GenericTypes > , full_path : & str , is_ref : bool , single_contained : Option < & syn:: Type > , var_name : & syn:: Ident , var_access : & str )
731
731
// Returns prefix + Vec<(prefix, var-name-to-inline-convert)> + suffix
732
732
// expecting one element in the vec per generic type, each of which is inline-converted
733
733
-> Option < ( & ' b str , Vec < ( String , String ) > , & ' b str ) > {
@@ -746,7 +746,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
746
746
} ,
747
747
"Option" => {
748
748
if let Some ( syn:: Type :: Path ( p) ) = single_contained {
749
- if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , None ) ) {
749
+ if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , generics ) ) {
750
750
if is_ref {
751
751
return Some ( ( "if " , vec ! [ ( ".inner.is_null() { None } else { Some((*" . to_string( ) , format!( "{}" , var_name) ) ] , ").clone()) }" ) )
752
752
} else {
@@ -757,7 +757,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
757
757
758
758
if let Some ( t) = single_contained {
759
759
let mut v = Vec :: new ( ) ;
760
- let needs_deref = self . write_empty_rust_val_check_suffix ( & mut v, t) ;
760
+ let needs_deref = self . write_empty_rust_val_check_suffix ( generics , & mut v, t) ;
761
761
let s = String :: from_utf8 ( v) . unwrap ( ) ;
762
762
if needs_deref {
763
763
return Some ( ( "if " , vec ! [
@@ -1023,10 +1023,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1023
1023
1024
1024
/// Prints a constructor for something which is "uninitialized" (but obviously not actually
1025
1025
/// unint'd memory).
1026
- pub fn write_empty_rust_val < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type ) {
1026
+ pub fn write_empty_rust_val < W : std:: io:: Write > ( & self , generics : Option < & GenericTypes > , w : & mut W , t : & syn:: Type ) {
1027
1027
match t {
1028
1028
syn:: Type :: Path ( p) => {
1029
- let resolved = self . resolve_path ( & p. path , None ) ;
1029
+ let resolved = self . resolve_path ( & p. path , generics ) ;
1030
1030
if self . crate_types . opaques . get ( & resolved) . is_some ( ) {
1031
1031
write ! ( w, "crate::{} {{ inner: std::ptr::null_mut(), is_owned: true }}" , resolved) . unwrap ( ) ;
1032
1032
} else {
@@ -1056,10 +1056,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1056
1056
/// Prints a suffix to determine if a variable is empty (ie was set by write_empty_rust_val),
1057
1057
/// returning whether we need to dereference the inner value before using it (ie it is a
1058
1058
/// pointer).
1059
- pub fn write_empty_rust_val_check_suffix < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type ) -> bool {
1059
+ pub fn write_empty_rust_val_check_suffix < W : std:: io:: Write > ( & self , generics : Option < & GenericTypes > , w : & mut W , t : & syn:: Type ) -> bool {
1060
1060
match t {
1061
1061
syn:: Type :: Path ( p) => {
1062
- let resolved = self . resolve_path ( & p. path , None ) ;
1062
+ let resolved = self . resolve_path ( & p. path , generics ) ;
1063
1063
if self . crate_types . opaques . get ( & resolved) . is_some ( ) {
1064
1064
write ! ( w, ".inner.is_null()" ) . unwrap ( ) ;
1065
1065
false
@@ -1092,11 +1092,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1092
1092
}
1093
1093
1094
1094
/// Prints a suffix to determine if a variable is empty (ie was set by write_empty_rust_val).
1095
- pub fn write_empty_rust_val_check < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type , var_access : & str ) {
1095
+ pub fn write_empty_rust_val_check < W : std:: io:: Write > ( & self , generics : Option < & GenericTypes > , w : & mut W , t : & syn:: Type , var_access : & str ) {
1096
1096
match t {
1097
1097
syn:: Type :: Path ( _) => {
1098
1098
write ! ( w, "{}" , var_access) . unwrap ( ) ;
1099
- self . write_empty_rust_val_check_suffix ( w, t) ;
1099
+ self . write_empty_rust_val_check_suffix ( generics , w, t) ;
1100
1100
} ,
1101
1101
syn:: Type :: Array ( a) => {
1102
1102
if let syn:: Expr :: Lit ( l) = & a. len {
@@ -1108,7 +1108,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1108
1108
self . from_c_conversion_prefix_from_path( & arrty, false ) . unwrap( ) ,
1109
1109
var_access,
1110
1110
self . from_c_conversion_suffix_from_path( & arrty, false ) . unwrap( ) ) . unwrap ( ) ;
1111
- self . write_empty_rust_val_check_suffix ( w, t) ;
1111
+ self . write_empty_rust_val_check_suffix ( generics , w, t) ;
1112
1112
} else { unimplemented ! ( ) ; }
1113
1113
} else { unimplemented ! ( ) ; }
1114
1114
}
@@ -1561,7 +1561,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1561
1561
pub fn write_to_c_conversion_new_var_inner < W : std:: io:: Write > ( & self , w : & mut W , ident : & syn:: Ident , var_access : & str , t : & syn:: Type , generics : Option < & GenericTypes > , ptr_for_ref : bool ) -> bool {
1562
1562
self . write_conversion_new_var_intern ( w, ident, var_access, t, generics, false , ptr_for_ref, true ,
1563
1563
& |a, b| self . to_c_conversion_new_var_from_path ( a, b) ,
1564
- & |a, b, c, d, e| self . to_c_conversion_container_new_var ( a, b, c, d, e) ,
1564
+ & |a, b, c, d, e| self . to_c_conversion_container_new_var ( generics , a, b, c, d, e) ,
1565
1565
// We force ptr_for_ref here since we can't generate a ref on one line and use it later
1566
1566
& |a, b, c, d, e, f| self . write_to_c_conversion_inline_prefix_inner ( a, b, c, d, e, f) ,
1567
1567
& |a, b, c, d, e, f| self . write_to_c_conversion_inline_suffix_inner ( a, b, c, d, e, f) )
@@ -1572,7 +1572,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1572
1572
pub fn write_from_c_conversion_new_var < W : std:: io:: Write > ( & self , w : & mut W , ident : & syn:: Ident , t : & syn:: Type , generics : Option < & GenericTypes > ) -> bool {
1573
1573
self . write_conversion_new_var_intern ( w, ident, & format ! ( "{}" , ident) , t, generics, false , false , false ,
1574
1574
& |a, b| self . from_c_conversion_new_var_from_path ( a, b) ,
1575
- & |a, b, c, d, e| self . from_c_conversion_container_new_var ( a, b, c, d, e) ,
1575
+ & |a, b, c, d, e| self . from_c_conversion_container_new_var ( generics , a, b, c, d, e) ,
1576
1576
// We force ptr_for_ref here since we can't generate a ref on one line and use it later
1577
1577
& |a, b, c, d, e, _f| self . write_from_c_conversion_prefix_inner ( a, b, c, d, e) ,
1578
1578
& |a, b, c, d, e, _f| self . write_from_c_conversion_suffix_inner ( a, b, c, d, e) )
0 commit comments