@@ -78,7 +78,7 @@ pub(crate) trait BridgeableType: Debug {
78
78
79
79
/// Get the Rust representation of this type.
80
80
/// For a string this might be `std::string::String`.
81
- fn to_rust_type_path ( & self ) -> TokenStream ;
81
+ fn to_rust_type_path ( & self , types : & TypeDeclarations ) -> TokenStream ;
82
82
83
83
/// Get the Swift representation of this type.
84
84
///
@@ -440,25 +440,8 @@ impl BridgeableType for BridgedType {
440
440
}
441
441
}
442
442
443
- /***
444
- fn extract_swift_result_variants(
445
- &self,
446
- type_pos: TypePosition,
447
- types: &TypeDeclarations,
448
- ) -> Option<(String, String)> {
449
- match self {
450
- BridgedType::StdLib(StdLibType::Result(result)) => Some((
451
- result.ok_ty.to_swift_type(type_pos, types),
452
- result.err_ty.to_swift_type(type_pos, types),
453
- )),
454
- BridgedType::Bridgeable(ty) => ty.extract_swift_result_variants(type_pos, types),
455
- _ => None,
456
- }
457
- }
458
- ***/
459
-
460
- fn to_rust_type_path ( & self ) -> TokenStream {
461
- self . to_rust_type_path ( )
443
+ fn to_rust_type_path ( & self , types : & TypeDeclarations ) -> TokenStream {
444
+ self . to_rust_type_path ( types)
462
445
}
463
446
464
447
fn to_swift_type ( & self , type_pos : TypePosition , types : & TypeDeclarations ) -> String {
@@ -783,58 +766,43 @@ impl BridgedType {
783
766
// U8 -> u8
784
767
// Vec<U32> -> Vec<u32>
785
768
// SomeOpaqueRustType -> super::SomeOpaqueRustType
786
- pub ( crate ) fn to_rust_type_path ( & self ) -> TokenStream {
769
+ pub ( crate ) fn to_rust_type_path ( & self , types : & TypeDeclarations ) -> TokenStream {
787
770
match self {
788
- BridgedType :: Bridgeable ( b) => b. to_rust_type_path ( ) ,
789
- BridgedType :: StdLib ( stdlib_type) => {
790
- match stdlib_type {
791
- StdLibType :: Null => {
792
- quote ! { ( ) }
793
- }
794
- StdLibType :: U8 => quote ! { u8 } ,
795
- StdLibType :: I8 => quote ! { i8 } ,
796
- StdLibType :: U16 => quote ! { u16 } ,
797
- StdLibType :: I16 => quote ! { i16 } ,
798
- StdLibType :: U32 => quote ! { u32 } ,
799
- StdLibType :: I32 => quote ! { i32 } ,
800
- StdLibType :: U64 => quote ! { u64 } ,
801
- StdLibType :: I64 => quote ! { i64 } ,
802
- StdLibType :: Usize => quote ! { usize } ,
803
- StdLibType :: Isize => quote ! { isize } ,
804
- StdLibType :: F32 => quote ! { f32 } ,
805
- StdLibType :: F64 => quote ! { f64 } ,
806
- StdLibType :: Bool => quote ! { bool } ,
807
- StdLibType :: Pointer ( ptr) => {
808
- let ptr_kind = & ptr. kind ;
809
-
810
- match & ptr. pointee {
811
- Pointee :: BuiltIn ( ty) => {
812
- let ty = ty. to_rust_type_path ( ) ;
813
- quote ! { #ptr_kind #ty}
814
- }
815
- Pointee :: Void ( _ty) => {
816
- // quote! { * #ptr_kind #ty };
817
- panic ! ( "Add a test case that hits this branch, then make it pass" )
818
- }
819
- }
820
- }
821
- StdLibType :: RefSlice ( ref_slice) => {
822
- let ty = ref_slice. ty . to_rust_type_path ( ) ;
823
- quote ! { & [ #ty] }
824
- }
825
- StdLibType :: Str => quote ! { & str } ,
826
- StdLibType :: Vec ( v) => {
827
- let ty = v. ty . to_rust_type_path ( ) ;
828
- quote ! { Vec <#ty> }
829
- }
830
- StdLibType :: Option ( opt) => {
831
- let ty = opt. ty . to_rust_type_path ( ) ;
832
- quote ! { Option <#ty> }
833
- }
834
- StdLibType :: Result ( result) => result. to_rust_type_path ( ) ,
835
- StdLibType :: BoxedFnOnce ( fn_once) => fn_once. to_rust_type_path ( ) ,
771
+ BridgedType :: Bridgeable ( b) => b. to_rust_type_path ( types) ,
772
+ BridgedType :: StdLib ( stdlib_type) => match stdlib_type {
773
+ StdLibType :: Null => {
774
+ quote ! { ( ) }
836
775
}
837
- }
776
+ StdLibType :: U8 => quote ! { u8 } ,
777
+ StdLibType :: I8 => quote ! { i8 } ,
778
+ StdLibType :: U16 => quote ! { u16 } ,
779
+ StdLibType :: I16 => quote ! { i16 } ,
780
+ StdLibType :: U32 => quote ! { u32 } ,
781
+ StdLibType :: I32 => quote ! { i32 } ,
782
+ StdLibType :: U64 => quote ! { u64 } ,
783
+ StdLibType :: I64 => quote ! { i64 } ,
784
+ StdLibType :: Usize => quote ! { usize } ,
785
+ StdLibType :: Isize => quote ! { isize } ,
786
+ StdLibType :: F32 => quote ! { f32 } ,
787
+ StdLibType :: F64 => quote ! { f64 } ,
788
+ StdLibType :: Bool => quote ! { bool } ,
789
+ StdLibType :: Pointer ( ptr) => ptr. to_rust_type_path ( types) ,
790
+ StdLibType :: RefSlice ( ref_slice) => {
791
+ let ty = ref_slice. ty . to_rust_type_path ( types) ;
792
+ quote ! { & [ #ty] }
793
+ }
794
+ StdLibType :: Str => quote ! { & str } ,
795
+ StdLibType :: Vec ( v) => {
796
+ let ty = v. ty . to_rust_type_path ( types) ;
797
+ quote ! { Vec <#ty> }
798
+ }
799
+ StdLibType :: Option ( opt) => {
800
+ let ty = opt. ty . to_rust_type_path ( types) ;
801
+ quote ! { Option <#ty> }
802
+ }
803
+ StdLibType :: Result ( result) => result. to_rust_type_path ( types) ,
804
+ StdLibType :: BoxedFnOnce ( fn_once) => fn_once. to_rust_type_path ( types) ,
805
+ } ,
838
806
BridgedType :: Foreign ( CustomBridgedType :: Shared ( SharedType :: Struct ( shared_struct) ) ) => {
839
807
let ty_name = & shared_struct. name ;
840
808
quote ! {
@@ -877,18 +845,7 @@ impl BridgedType {
877
845
StdLibType :: Isize => quote ! { isize } ,
878
846
StdLibType :: Bool => quote ! { bool } ,
879
847
StdLibType :: Pointer ( ptr) => {
880
- let kind = ptr. kind . to_token_stream ( ) ;
881
-
882
- let ty = match & ptr. pointee {
883
- Pointee :: BuiltIn ( ty) => {
884
- ty. to_ffi_compatible_rust_type ( swift_bridge_path, types)
885
- }
886
- Pointee :: Void ( ty) => {
887
- quote ! { super :: #ty }
888
- }
889
- } ;
890
-
891
- quote ! { #kind #ty}
848
+ ptr. to_ffi_compatible_rust_type ( swift_bridge_path, types)
892
849
}
893
850
StdLibType :: RefSlice ( slice) => {
894
851
let ty = slice
@@ -903,7 +860,7 @@ impl BridgedType {
903
860
quote ! { ( ) }
904
861
}
905
862
StdLibType :: Vec ( ty) => {
906
- let ty = ty. ty . to_rust_type_path ( ) ;
863
+ let ty = ty. ty . to_rust_type_path ( types ) ;
907
864
quote ! { * mut Vec <#ty> }
908
865
}
909
866
StdLibType :: Option ( opt) => match opt. ty . deref ( ) {
@@ -963,7 +920,7 @@ impl BridgedType {
963
920
quote ! { #swift_bridge_path:: string:: RustStr }
964
921
}
965
922
StdLibType :: Vec ( ty) => {
966
- let ty = ty. ty . to_rust_type_path ( ) ;
923
+ let ty = ty. ty . to_rust_type_path ( types ) ;
967
924
quote ! { * mut Vec <#ty> }
968
925
}
969
926
StdLibType :: Option ( _) => {
@@ -990,7 +947,7 @@ impl BridgedType {
990
947
}
991
948
} ,
992
949
StdLibType :: Result ( result) => result. to_ffi_compatible_rust_type ( swift_bridge_path) ,
993
- StdLibType :: BoxedFnOnce ( fn_once) => fn_once. to_ffi_compatible_rust_type ( ) ,
950
+ StdLibType :: BoxedFnOnce ( fn_once) => fn_once. to_ffi_compatible_rust_type ( types ) ,
994
951
} ,
995
952
BridgedType :: Foreign ( CustomBridgedType :: Shared ( SharedType :: Struct ( shared_struct) ) ) => {
996
953
let ty_name = & shared_struct. name ;
@@ -1223,26 +1180,13 @@ impl BridgedType {
1223
1180
/// unsafe { __swift_bridge__void_pointers(arg1) }
1224
1181
/// }
1225
1182
///
1226
- pub fn maybe_convert_pointer_to_super_pointer ( & self ) -> TokenStream {
1183
+ pub fn maybe_convert_pointer_to_super_pointer ( & self , types : & TypeDeclarations ) -> TokenStream {
1227
1184
match self {
1228
- BridgedType :: StdLib ( stdlib_type) => {
1229
- match stdlib_type {
1230
- StdLibType :: Pointer ( pointer) => match & pointer. pointee {
1231
- Pointee :: BuiltIn ( _built_in) => {
1232
- //
1233
- self . to_rust_type_path ( )
1234
- }
1235
- Pointee :: Void ( _) => {
1236
- let pointer_kind = & pointer. kind ;
1237
- let pointee = & pointer. pointee ;
1238
-
1239
- quote ! { #pointer_kind super :: #pointee }
1240
- }
1241
- } ,
1242
- _ => self . to_rust_type_path ( ) ,
1243
- }
1244
- }
1245
- _ => self . to_rust_type_path ( ) ,
1185
+ BridgedType :: StdLib ( stdlib_type) => match stdlib_type {
1186
+ StdLibType :: Pointer ( pointer) => pointer. to_rust_type_path ( types) ,
1187
+ _ => self . to_rust_type_path ( types) ,
1188
+ } ,
1189
+ _ => self . to_rust_type_path ( types) ,
1246
1190
}
1247
1191
}
1248
1192
@@ -1307,7 +1251,7 @@ impl BridgedType {
1307
1251
span,
1308
1252
) ,
1309
1253
StdLibType :: BoxedFnOnce ( fn_once) => {
1310
- fn_once. convert_rust_value_to_ffi_compatible_value ( expression)
1254
+ fn_once. convert_rust_value_to_ffi_compatible_value ( expression, types )
1311
1255
}
1312
1256
} ,
1313
1257
BridgedType :: Foreign ( CustomBridgedType :: Shared ( SharedType :: Struct ( shared_struct) ) ) => {
0 commit comments