@@ -153,7 +153,7 @@ fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
153
153
}
154
154
155
155
// Protocol for types that transfer other types across the FFI. This is
156
- // analogous go the Rust trait of the same name.
156
+ // analogous to the Rust trait of the same name.
157
157
fileprivate protocol FfiConverter {
158
158
associatedtype FfiType
159
159
associatedtype SwiftType
@@ -253,18 +253,19 @@ fileprivate extension RustCallStatus {
253
253
}
254
254
255
255
private func rustCall< T> ( _ callback: ( UnsafeMutablePointer < RustCallStatus > ) -> T ) throws -> T {
256
- try makeRustCall ( callback, errorHandler: nil )
256
+ let neverThrow : ( ( RustBuffer ) throws -> Never ) ? = nil
257
+ return try makeRustCall ( callback, errorHandler: neverThrow)
257
258
}
258
259
259
- private func rustCallWithError< T> (
260
- _ errorHandler: @escaping ( RustBuffer ) throws -> Error ,
260
+ private func rustCallWithError< T, E : Swift . Error > (
261
+ _ errorHandler: @escaping ( RustBuffer ) throws -> E ,
261
262
_ callback: ( UnsafeMutablePointer < RustCallStatus > ) -> T ) throws -> T {
262
263
try makeRustCall ( callback, errorHandler: errorHandler)
263
264
}
264
265
265
- private func makeRustCall< T> (
266
+ private func makeRustCall< T, E : Swift . Error > (
266
267
_ callback: ( UnsafeMutablePointer < RustCallStatus > ) -> T ,
267
- errorHandler: ( ( RustBuffer ) throws -> Error ) ?
268
+ errorHandler: ( ( RustBuffer ) throws -> E ) ?
268
269
) throws -> T {
269
270
uniffiEnsureInitialized ( )
270
271
var callStatus = RustCallStatus . init ( )
@@ -273,9 +274,9 @@ private func makeRustCall<T>(
273
274
return returnedVal
274
275
}
275
276
276
- private func uniffiCheckCallStatus(
277
+ private func uniffiCheckCallStatus< E : Swift . Error > (
277
278
callStatus: RustCallStatus ,
278
- errorHandler: ( ( RustBuffer ) throws -> Error ) ?
279
+ errorHandler: ( ( RustBuffer ) throws -> E ) ?
279
280
) throws {
280
281
switch callStatus. code {
281
282
case CALL_SUCCESS:
@@ -903,54 +904,63 @@ extension PaginatorState: Equatable, Hashable {}
903
904
904
905
905
906
906
- // Note that we don't yet support `indirect` for enums.
907
- // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
907
+
908
908
/**
909
909
* The error type for failures while trying to log in a new device using a QR
910
910
* code.
911
911
*/
912
-
913
912
public enum QrCodeLoginError {
913
+
914
+
914
915
915
916
/**
916
917
* An error happened while we were communicating with the OIDC provider.
917
918
*/
918
- case oidc
919
+ case Oidc( message: String )
920
+
919
921
/**
920
922
* The other device has signaled to us that the login has failed.
921
923
*/
922
- case loginFailure
924
+ case LoginFailure( message: String )
925
+
923
926
/**
924
927
* An unexpected message was received from the other device.
925
928
*/
926
- case unexpectedMessage
929
+ case UnexpectedMessage( message: String )
930
+
927
931
/**
928
932
* An error happened while exchanging messages with the other device.
929
933
*/
930
- case secureChannel
934
+ case SecureChannel( message: String )
935
+
931
936
/**
932
937
* The cross-process refresh lock failed to be initialized.
933
938
*/
934
- case crossProcessRefreshLock
939
+ case CrossProcessRefreshLock( message: String )
940
+
935
941
/**
936
942
* An error happened while we were trying to discover our user and device
937
943
* ID, after we have acquired an access token from the OIDC provider.
938
944
*/
939
- case userIdDiscovery
945
+ case UserIdDiscovery( message: String )
946
+
940
947
/**
941
948
* We failed to set the session tokens after we figured out our device and
942
949
* user IDs.
943
950
*/
944
- case sessionTokens
951
+ case SessionTokens( message: String )
952
+
945
953
/**
946
954
* The device keys failed to be uploaded after we successfully logged in.
947
955
*/
948
- case deviceKeyUpload
956
+ case DeviceKeyUpload( message: String )
957
+
949
958
/**
950
959
* The secrets bundle we received from the existing device failed to be
951
960
* imported.
952
961
*/
953
- case secretImport
962
+ case SecretImport( message: String )
963
+
954
964
}
955
965
956
966
@@ -960,86 +970,89 @@ public struct FfiConverterTypeQRCodeLoginError: FfiConverterRustBuffer {
960
970
public static func read( from buf: inout ( data: Data , offset: Data . Index ) ) throws -> QrCodeLoginError {
961
971
let variant : Int32 = try readInt ( & buf)
962
972
switch variant {
973
+
963
974
964
- case 1 : return . oidc
975
+
965
976
966
- case 2 : return . loginFailure
977
+ case 1 : return . Oidc(
978
+ message: try FfiConverterString . read ( from: & buf)
979
+ )
967
980
968
- case 3 : return . unexpectedMessage
981
+ case 2 : return . LoginFailure(
982
+ message: try FfiConverterString . read ( from: & buf)
983
+ )
969
984
970
- case 4 : return . secureChannel
985
+ case 3 : return . UnexpectedMessage(
986
+ message: try FfiConverterString . read ( from: & buf)
987
+ )
988
+
989
+ case 4 : return . SecureChannel(
990
+ message: try FfiConverterString . read ( from: & buf)
991
+ )
971
992
972
- case 5 : return . crossProcessRefreshLock
993
+ case 5 : return . CrossProcessRefreshLock(
994
+ message: try FfiConverterString . read ( from: & buf)
995
+ )
973
996
974
- case 6 : return . userIdDiscovery
997
+ case 6 : return . UserIdDiscovery(
998
+ message: try FfiConverterString . read ( from: & buf)
999
+ )
975
1000
976
- case 7 : return . sessionTokens
1001
+ case 7 : return . SessionTokens(
1002
+ message: try FfiConverterString . read ( from: & buf)
1003
+ )
977
1004
978
- case 8 : return . deviceKeyUpload
1005
+ case 8 : return . DeviceKeyUpload(
1006
+ message: try FfiConverterString . read ( from: & buf)
1007
+ )
979
1008
980
- case 9 : return . secretImport
1009
+ case 9 : return . SecretImport(
1010
+ message: try FfiConverterString . read ( from: & buf)
1011
+ )
981
1012
1013
+
982
1014
default : throw UniffiInternalError . unexpectedEnumCase
983
1015
}
984
1016
}
985
1017
986
1018
public static func write( _ value: QrCodeLoginError , into buf: inout [ UInt8 ] ) {
987
1019
switch value {
1020
+
988
1021
1022
+
989
1023
990
- case . oidc :
1024
+ case . Oidc ( _ /* message is ignored*/ ) :
991
1025
writeInt ( & buf, Int32 ( 1 ) )
992
-
993
-
994
- case . loginFailure:
1026
+ case . LoginFailure( _ /* message is ignored*/) :
995
1027
writeInt ( & buf, Int32 ( 2 ) )
996
-
997
-
998
- case . unexpectedMessage:
1028
+ case . UnexpectedMessage( _ /* message is ignored*/) :
999
1029
writeInt ( & buf, Int32 ( 3 ) )
1000
-
1001
-
1002
- case . secureChannel:
1030
+ case . SecureChannel( _ /* message is ignored*/) :
1003
1031
writeInt ( & buf, Int32 ( 4 ) )
1004
-
1005
-
1006
- case . crossProcessRefreshLock:
1032
+ case . CrossProcessRefreshLock( _ /* message is ignored*/) :
1007
1033
writeInt ( & buf, Int32 ( 5 ) )
1008
-
1009
-
1010
- case . userIdDiscovery:
1034
+ case . UserIdDiscovery( _ /* message is ignored*/) :
1011
1035
writeInt ( & buf, Int32 ( 6 ) )
1012
-
1013
-
1014
- case . sessionTokens:
1036
+ case . SessionTokens( _ /* message is ignored*/) :
1015
1037
writeInt ( & buf, Int32 ( 7 ) )
1016
-
1017
-
1018
- case . deviceKeyUpload:
1038
+ case . DeviceKeyUpload( _ /* message is ignored*/) :
1019
1039
writeInt ( & buf, Int32 ( 8 ) )
1020
-
1021
-
1022
- case . secretImport:
1040
+ case . SecretImport( _ /* message is ignored*/) :
1023
1041
writeInt ( & buf, Int32 ( 9 ) )
1042
+
1024
1043
1025
1044
}
1026
1045
}
1027
1046
}
1028
1047
1029
1048
1030
- public func FfiConverterTypeQRCodeLoginError_lift( _ buf: RustBuffer ) throws -> QrCodeLoginError {
1031
- return try FfiConverterTypeQRCodeLoginError . lift ( buf)
1032
- }
1033
-
1034
- public func FfiConverterTypeQRCodeLoginError_lower( _ value: QrCodeLoginError ) -> RustBuffer {
1035
- return FfiConverterTypeQRCodeLoginError . lower ( value)
1036
- }
1037
-
1038
-
1039
-
1040
1049
extension QrCodeLoginError : Equatable , Hashable { }
1041
1050
1042
-
1051
+ extension QrCodeLoginError : Foundation . LocalizedError {
1052
+ public var errorDescription : String ? {
1053
+ String ( reflecting: self )
1054
+ }
1055
+ }
1043
1056
1044
1057
// Note that we don't yet support `indirect` for enums.
1045
1058
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
@@ -1141,9 +1154,9 @@ private enum InitializationResult {
1141
1154
case contractVersionMismatch
1142
1155
case apiChecksumMismatch
1143
1156
}
1144
- // Use a global variables to perform the versioning checks. Swift ensures that
1157
+ // Use a global variable to perform the versioning checks. Swift ensures that
1145
1158
// the code inside is only computed once.
1146
- private var initializationResult : InitializationResult {
1159
+ private var initializationResult : InitializationResult = {
1147
1160
// Get the bindings contract version from our ComponentInterface
1148
1161
let bindings_contract_version = 26
1149
1162
// Get the scaffolding contract version by calling the into the dylib
@@ -1156,7 +1169,7 @@ private var initializationResult: InitializationResult {
1156
1169
}
1157
1170
1158
1171
return InitializationResult . ok
1159
- }
1172
+ } ( )
1160
1173
1161
1174
private func uniffiEnsureInitialized( ) {
1162
1175
switch initializationResult {
0 commit comments