@@ -117,7 +117,12 @@ pub(crate) trait BridgeableType: Debug {
117
117
/// Get the Swift representation of this type.
118
118
///
119
119
/// For example, `Result<String, ()>` would become `RustResult<String, ()>`
120
- fn to_swift_type ( & self , type_pos : TypePosition , types : & TypeDeclarations ) -> String ;
120
+ fn to_swift_type (
121
+ & self ,
122
+ type_pos : TypePosition ,
123
+ types : & TypeDeclarations ,
124
+ swift_bridge_path : & Path ,
125
+ ) -> String ;
121
126
122
127
/// Get the C representation of this type.
123
128
fn to_c_type ( & self , types : & TypeDeclarations ) -> String ;
@@ -146,6 +151,7 @@ pub(crate) trait BridgeableType: Debug {
146
151
/// Get the FFI compatible Option<Self> representation.
147
152
fn to_ffi_compatible_option_swift_type (
148
153
& self ,
154
+ type_pos : TypePosition ,
149
155
swift_bridge_path : & Path ,
150
156
types : & TypeDeclarations ,
151
157
) -> String ;
@@ -207,6 +213,7 @@ pub(crate) trait BridgeableType: Debug {
207
213
expression : & str ,
208
214
type_pos : TypePosition ,
209
215
types : & TypeDeclarations ,
216
+ swift_bridge_path : & Path ,
210
217
) -> String ;
211
218
212
219
/// Convert an Option<Self> FFI representation to the Rust representation.
@@ -285,6 +292,8 @@ pub(crate) trait BridgeableType: Debug {
285
292
/// of checking the type.
286
293
fn contains_ref_string_recursive ( & self ) -> bool ;
287
294
295
+ // TODO: Is this used? Do we need this?
296
+ #[ allow( unused) ]
288
297
/// Parse the type from a `FnArg`.
289
298
fn from_fn_arg (
290
299
fn_arg : & FnArg ,
@@ -532,8 +541,13 @@ impl BridgeableType for BridgedType {
532
541
self . to_rust_type_path ( types)
533
542
}
534
543
535
- fn to_swift_type ( & self , type_pos : TypePosition , types : & TypeDeclarations ) -> String {
536
- self . to_swift_type ( type_pos, types)
544
+ fn to_swift_type (
545
+ & self ,
546
+ type_pos : TypePosition ,
547
+ types : & TypeDeclarations ,
548
+ swift_bridge_path : & Path ,
549
+ ) -> String {
550
+ self . to_swift_type ( type_pos, types, swift_bridge_path)
537
551
}
538
552
539
553
fn to_c_type ( & self , types : & TypeDeclarations ) -> String {
@@ -562,6 +576,7 @@ impl BridgeableType for BridgedType {
562
576
563
577
fn to_ffi_compatible_option_swift_type (
564
578
& self ,
579
+ _type_pos : TypePosition ,
565
580
_swift_bridge_path : & Path ,
566
581
_types : & TypeDeclarations ,
567
582
) -> String {
@@ -626,8 +641,9 @@ impl BridgeableType for BridgedType {
626
641
expression : & str ,
627
642
type_pos : TypePosition ,
628
643
types : & TypeDeclarations ,
644
+ swift_bridge_path : & Path ,
629
645
) -> String {
630
- self . convert_ffi_value_to_swift_value ( expression, type_pos, types)
646
+ self . convert_ffi_value_to_swift_value ( expression, type_pos, types, swift_bridge_path )
631
647
}
632
648
633
649
fn convert_ffi_option_expression_to_swift_type ( & self , _expression : & str ) -> String {
@@ -1091,9 +1107,14 @@ impl BridgedType {
1091
1107
// U8 -> UInt8
1092
1108
// *const u32 -> UnsafePointer<UInt32>
1093
1109
// ... etc
1094
- pub fn to_swift_type ( & self , type_pos : TypePosition , types : & TypeDeclarations ) -> String {
1110
+ pub fn to_swift_type (
1111
+ & self ,
1112
+ type_pos : TypePosition ,
1113
+ types : & TypeDeclarations ,
1114
+ swift_bridge_path : & Path ,
1115
+ ) -> String {
1095
1116
match self {
1096
- BridgedType :: Bridgeable ( b) => b. to_swift_type ( type_pos, types) ,
1117
+ BridgedType :: Bridgeable ( b) => b. to_swift_type ( type_pos, types, swift_bridge_path ) ,
1097
1118
BridgedType :: StdLib ( stdlib_type) => match stdlib_type {
1098
1119
StdLibType :: U8 => "UInt8" . to_string ( ) ,
1099
1120
StdLibType :: I8 => "Int8" . to_string ( ) ,
@@ -1119,7 +1140,7 @@ impl BridgedType {
1119
1140
format ! (
1120
1141
"Unsafe{}Pointer<{}>" ,
1121
1142
maybe_mutable,
1122
- ty. to_swift_type( type_pos, types)
1143
+ ty. to_swift_type( type_pos, types, swift_bridge_path )
1123
1144
)
1124
1145
}
1125
1146
Pointee :: Void ( _) => {
@@ -1136,7 +1157,7 @@ impl BridgedType {
1136
1157
} else {
1137
1158
format ! (
1138
1159
"UnsafeBufferPointer<{}>" ,
1139
- slice. ty. to_swift_type( type_pos, types)
1160
+ slice. ty. to_swift_type( type_pos, types, swift_bridge_path )
1140
1161
)
1141
1162
}
1142
1163
}
@@ -1167,26 +1188,37 @@ impl BridgedType {
1167
1188
StdLibType :: Vec ( ty) => match type_pos {
1168
1189
TypePosition :: FnArg ( func_host_lang, _) => {
1169
1190
if func_host_lang. is_rust ( ) {
1170
- format ! ( "RustVec<{}>" , ty. ty. to_swift_type( type_pos, types) )
1191
+ format ! (
1192
+ "RustVec<{}>" ,
1193
+ ty. ty. to_swift_type( type_pos, types, swift_bridge_path)
1194
+ )
1171
1195
} else {
1172
1196
"UnsafeMutableRawPointer" . to_string ( )
1173
1197
}
1174
1198
}
1175
1199
TypePosition :: FnReturn ( func_host_lang) => {
1176
1200
if func_host_lang. is_rust ( ) {
1177
- format ! ( "RustVec<{}>" , ty. ty. to_swift_type( type_pos, types) )
1201
+ format ! (
1202
+ "RustVec<{}>" ,
1203
+ ty. ty. to_swift_type( type_pos, types, swift_bridge_path)
1204
+ )
1178
1205
} else {
1179
1206
"UnsafeMutableRawPointer" . to_string ( )
1180
1207
}
1181
1208
}
1182
1209
_ => {
1183
- format ! ( "RustVec<{}>" , ty. ty. to_swift_type( type_pos, types) )
1210
+ format ! (
1211
+ "RustVec<{}>" ,
1212
+ ty. ty. to_swift_type( type_pos, types, swift_bridge_path)
1213
+ )
1184
1214
}
1185
1215
} ,
1186
- StdLibType :: Option ( opt) => opt. to_swift_type ( type_pos, types) ,
1187
- StdLibType :: Result ( result) => result. to_swift_type ( type_pos, types) ,
1216
+ StdLibType :: Option ( opt) => opt. to_swift_type ( swift_bridge_path, type_pos, types) ,
1217
+ StdLibType :: Result ( result) => {
1218
+ result. to_swift_type ( type_pos, types, swift_bridge_path)
1219
+ }
1188
1220
StdLibType :: BoxedFnOnce ( boxed_fn) => boxed_fn. to_swift_type ( ) . to_string ( ) ,
1189
- StdLibType :: Tuple ( tuple) => tuple. to_swift_type ( type_pos, types) ,
1221
+ StdLibType :: Tuple ( tuple) => tuple. to_swift_type ( type_pos, types, swift_bridge_path ) ,
1190
1222
} ,
1191
1223
BridgedType :: Foreign ( CustomBridgedType :: Shared ( SharedType :: Struct ( shared_struct) ) ) => {
1192
1224
match type_pos {
@@ -1482,11 +1514,15 @@ impl BridgedType {
1482
1514
expression : & str ,
1483
1515
type_pos : TypePosition ,
1484
1516
types : & TypeDeclarations ,
1517
+ swift_bridge_path : & Path ,
1485
1518
) -> String {
1486
1519
match self {
1487
- BridgedType :: Bridgeable ( b) => {
1488
- b. convert_ffi_expression_to_swift_type ( expression, type_pos, types)
1489
- }
1520
+ BridgedType :: Bridgeable ( b) => b. convert_ffi_expression_to_swift_type (
1521
+ expression,
1522
+ type_pos,
1523
+ types,
1524
+ swift_bridge_path,
1525
+ ) ,
1490
1526
BridgedType :: StdLib ( stdlib_type) => match stdlib_type {
1491
1527
StdLibType :: Null
1492
1528
| StdLibType :: U8
@@ -1530,23 +1566,29 @@ impl BridgedType {
1530
1566
format ! (
1531
1567
"let slice = {value}; return UnsafeBufferPointer(start: slice.start.assumingMemoryBound(to: {ty}.self), count: Int(slice.len));" ,
1532
1568
value = expression,
1533
- ty = ty. ty. to_swift_type( type_pos, types)
1569
+ ty = ty. ty. to_swift_type( type_pos, types, swift_bridge_path )
1534
1570
)
1535
1571
}
1536
1572
StdLibType :: Str => expression. to_string ( ) ,
1537
1573
StdLibType :: Vec ( _ty) => {
1538
1574
format ! ( "RustVec(ptr: {})" , expression)
1539
1575
}
1540
1576
StdLibType :: Option ( opt) => opt. convert_ffi_expression_to_swift_type ( expression) ,
1541
- StdLibType :: Result ( result) => {
1542
- result. convert_ffi_value_to_swift_value ( expression, type_pos, types)
1543
- }
1577
+ StdLibType :: Result ( result) => result. convert_ffi_value_to_swift_value (
1578
+ expression,
1579
+ type_pos,
1580
+ types,
1581
+ swift_bridge_path,
1582
+ ) ,
1544
1583
StdLibType :: BoxedFnOnce ( fn_once) => {
1545
1584
fn_once. convert_ffi_value_to_swift_value ( type_pos)
1546
1585
}
1547
- StdLibType :: Tuple ( tuple) => {
1548
- tuple. convert_ffi_expression_to_swift_type ( expression, type_pos, types)
1549
- }
1586
+ StdLibType :: Tuple ( tuple) => tuple. convert_ffi_expression_to_swift_type (
1587
+ expression,
1588
+ type_pos,
1589
+ types,
1590
+ swift_bridge_path,
1591
+ ) ,
1550
1592
} ,
1551
1593
BridgedType :: Foreign ( CustomBridgedType :: Shared ( SharedType :: Struct ( shared_struct) ) ) => {
1552
1594
shared_struct. convert_ffi_expression_to_swift_type ( expression)
0 commit comments