Skip to content

Commit 497a868

Browse files
committed
Bump to version v1.2.0 (matrix-rust-sdk/main 7f02447c784da0884a02782e20500cae5785faaa)
1 parent 3f294cd commit 497a868

7 files changed

+2640
-445
lines changed

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// swift-tools-version:5.5
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33
import PackageDescription
4-
let checksum = "5d3a37a716ac04d2991ee224e55bcacfb8ede66ef7e782175505ad5a096033b3"
5-
let version = "v1.1.69"
4+
let checksum = "9e046a84b8ad0aff5fdcd65ee50b803989dd49fa440bafa53a2c9b5a8f42c4ba"
5+
let version = "v1.2.0"
66
let url = "https://github.com/matrix-org/matrix-rust-components-swift/releases/download/\(version)/MatrixSDKFFI.xcframework.zip"
77
let package = Package(
88
name: "MatrixRustSDK",

Sources/MatrixRustSDK/matrix_sdk.swift

+81-68
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
153153
}
154154

155155
// 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.
157157
fileprivate protocol FfiConverter {
158158
associatedtype FfiType
159159
associatedtype SwiftType
@@ -253,18 +253,19 @@ fileprivate extension RustCallStatus {
253253
}
254254

255255
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)
257258
}
258259

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,
261262
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
262263
try makeRustCall(callback, errorHandler: errorHandler)
263264
}
264265

265-
private func makeRustCall<T>(
266+
private func makeRustCall<T, E: Swift.Error>(
266267
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
267-
errorHandler: ((RustBuffer) throws -> Error)?
268+
errorHandler: ((RustBuffer) throws -> E)?
268269
) throws -> T {
269270
uniffiEnsureInitialized()
270271
var callStatus = RustCallStatus.init()
@@ -273,9 +274,9 @@ private func makeRustCall<T>(
273274
return returnedVal
274275
}
275276

276-
private func uniffiCheckCallStatus(
277+
private func uniffiCheckCallStatus<E: Swift.Error>(
277278
callStatus: RustCallStatus,
278-
errorHandler: ((RustBuffer) throws -> Error)?
279+
errorHandler: ((RustBuffer) throws -> E)?
279280
) throws {
280281
switch callStatus.code {
281282
case CALL_SUCCESS:
@@ -903,54 +904,63 @@ extension PaginatorState: Equatable, Hashable {}
903904

904905

905906

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+
908908
/**
909909
* The error type for failures while trying to log in a new device using a QR
910910
* code.
911911
*/
912-
913912
public enum QrCodeLoginError {
913+
914+
914915

915916
/**
916917
* An error happened while we were communicating with the OIDC provider.
917918
*/
918-
case oidc
919+
case Oidc(message: String)
920+
919921
/**
920922
* The other device has signaled to us that the login has failed.
921923
*/
922-
case loginFailure
924+
case LoginFailure(message: String)
925+
923926
/**
924927
* An unexpected message was received from the other device.
925928
*/
926-
case unexpectedMessage
929+
case UnexpectedMessage(message: String)
930+
927931
/**
928932
* An error happened while exchanging messages with the other device.
929933
*/
930-
case secureChannel
934+
case SecureChannel(message: String)
935+
931936
/**
932937
* The cross-process refresh lock failed to be initialized.
933938
*/
934-
case crossProcessRefreshLock
939+
case CrossProcessRefreshLock(message: String)
940+
935941
/**
936942
* An error happened while we were trying to discover our user and device
937943
* ID, after we have acquired an access token from the OIDC provider.
938944
*/
939-
case userIdDiscovery
945+
case UserIdDiscovery(message: String)
946+
940947
/**
941948
* We failed to set the session tokens after we figured out our device and
942949
* user IDs.
943950
*/
944-
case sessionTokens
951+
case SessionTokens(message: String)
952+
945953
/**
946954
* The device keys failed to be uploaded after we successfully logged in.
947955
*/
948-
case deviceKeyUpload
956+
case DeviceKeyUpload(message: String)
957+
949958
/**
950959
* The secrets bundle we received from the existing device failed to be
951960
* imported.
952961
*/
953-
case secretImport
962+
case SecretImport(message: String)
963+
954964
}
955965

956966

@@ -960,86 +970,89 @@ public struct FfiConverterTypeQRCodeLoginError: FfiConverterRustBuffer {
960970
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> QrCodeLoginError {
961971
let variant: Int32 = try readInt(&buf)
962972
switch variant {
973+
963974

964-
case 1: return .oidc
975+
965976

966-
case 2: return .loginFailure
977+
case 1: return .Oidc(
978+
message: try FfiConverterString.read(from: &buf)
979+
)
967980

968-
case 3: return .unexpectedMessage
981+
case 2: return .LoginFailure(
982+
message: try FfiConverterString.read(from: &buf)
983+
)
969984

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+
)
971992

972-
case 5: return .crossProcessRefreshLock
993+
case 5: return .CrossProcessRefreshLock(
994+
message: try FfiConverterString.read(from: &buf)
995+
)
973996

974-
case 6: return .userIdDiscovery
997+
case 6: return .UserIdDiscovery(
998+
message: try FfiConverterString.read(from: &buf)
999+
)
9751000

976-
case 7: return .sessionTokens
1001+
case 7: return .SessionTokens(
1002+
message: try FfiConverterString.read(from: &buf)
1003+
)
9771004

978-
case 8: return .deviceKeyUpload
1005+
case 8: return .DeviceKeyUpload(
1006+
message: try FfiConverterString.read(from: &buf)
1007+
)
9791008

980-
case 9: return .secretImport
1009+
case 9: return .SecretImport(
1010+
message: try FfiConverterString.read(from: &buf)
1011+
)
9811012

1013+
9821014
default: throw UniffiInternalError.unexpectedEnumCase
9831015
}
9841016
}
9851017

9861018
public static func write(_ value: QrCodeLoginError, into buf: inout [UInt8]) {
9871019
switch value {
1020+
9881021

1022+
9891023

990-
case .oidc:
1024+
case .Oidc(_ /* message is ignored*/):
9911025
writeInt(&buf, Int32(1))
992-
993-
994-
case .loginFailure:
1026+
case .LoginFailure(_ /* message is ignored*/):
9951027
writeInt(&buf, Int32(2))
996-
997-
998-
case .unexpectedMessage:
1028+
case .UnexpectedMessage(_ /* message is ignored*/):
9991029
writeInt(&buf, Int32(3))
1000-
1001-
1002-
case .secureChannel:
1030+
case .SecureChannel(_ /* message is ignored*/):
10031031
writeInt(&buf, Int32(4))
1004-
1005-
1006-
case .crossProcessRefreshLock:
1032+
case .CrossProcessRefreshLock(_ /* message is ignored*/):
10071033
writeInt(&buf, Int32(5))
1008-
1009-
1010-
case .userIdDiscovery:
1034+
case .UserIdDiscovery(_ /* message is ignored*/):
10111035
writeInt(&buf, Int32(6))
1012-
1013-
1014-
case .sessionTokens:
1036+
case .SessionTokens(_ /* message is ignored*/):
10151037
writeInt(&buf, Int32(7))
1016-
1017-
1018-
case .deviceKeyUpload:
1038+
case .DeviceKeyUpload(_ /* message is ignored*/):
10191039
writeInt(&buf, Int32(8))
1020-
1021-
1022-
case .secretImport:
1040+
case .SecretImport(_ /* message is ignored*/):
10231041
writeInt(&buf, Int32(9))
1042+
10241043

10251044
}
10261045
}
10271046
}
10281047

10291048

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-
10401049
extension QrCodeLoginError: Equatable, Hashable {}
10411050

1042-
1051+
extension QrCodeLoginError: Foundation.LocalizedError {
1052+
public var errorDescription: String? {
1053+
String(reflecting: self)
1054+
}
1055+
}
10431056

10441057
// Note that we don't yet support `indirect` for enums.
10451058
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
@@ -1141,9 +1154,9 @@ private enum InitializationResult {
11411154
case contractVersionMismatch
11421155
case apiChecksumMismatch
11431156
}
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
11451158
// the code inside is only computed once.
1146-
private var initializationResult: InitializationResult {
1159+
private var initializationResult: InitializationResult = {
11471160
// Get the bindings contract version from our ComponentInterface
11481161
let bindings_contract_version = 26
11491162
// Get the scaffolding contract version by calling the into the dylib
@@ -1156,7 +1169,7 @@ private var initializationResult: InitializationResult {
11561169
}
11571170

11581171
return InitializationResult.ok
1159-
}
1172+
}()
11601173

11611174
private func uniffiEnsureInitialized() {
11621175
switch initializationResult {

Sources/MatrixRustSDK/matrix_sdk_base.swift

+12-11
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
153153
}
154154

155155
// 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.
157157
fileprivate protocol FfiConverter {
158158
associatedtype FfiType
159159
associatedtype SwiftType
@@ -253,18 +253,19 @@ fileprivate extension RustCallStatus {
253253
}
254254

255255
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)
257258
}
258259

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,
261262
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
262263
try makeRustCall(callback, errorHandler: errorHandler)
263264
}
264265

265-
private func makeRustCall<T>(
266+
private func makeRustCall<T, E: Swift.Error>(
266267
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
267-
errorHandler: ((RustBuffer) throws -> Error)?
268+
errorHandler: ((RustBuffer) throws -> E)?
268269
) throws -> T {
269270
uniffiEnsureInitialized()
270271
var callStatus = RustCallStatus.init()
@@ -273,9 +274,9 @@ private func makeRustCall<T>(
273274
return returnedVal
274275
}
275276

276-
private func uniffiCheckCallStatus(
277+
private func uniffiCheckCallStatus<E: Swift.Error>(
277278
callStatus: RustCallStatus,
278-
errorHandler: ((RustBuffer) throws -> Error)?
279+
errorHandler: ((RustBuffer) throws -> E)?
279280
) throws {
280281
switch callStatus.code {
281282
case CALL_SUCCESS:
@@ -424,9 +425,9 @@ private enum InitializationResult {
424425
case contractVersionMismatch
425426
case apiChecksumMismatch
426427
}
427-
// Use a global variables to perform the versioning checks. Swift ensures that
428+
// Use a global variable to perform the versioning checks. Swift ensures that
428429
// the code inside is only computed once.
429-
private var initializationResult: InitializationResult {
430+
private var initializationResult: InitializationResult = {
430431
// Get the bindings contract version from our ComponentInterface
431432
let bindings_contract_version = 26
432433
// Get the scaffolding contract version by calling the into the dylib
@@ -436,7 +437,7 @@ private var initializationResult: InitializationResult {
436437
}
437438

438439
return InitializationResult.ok
439-
}
440+
}()
440441

441442
private func uniffiEnsureInitialized() {
442443
switch initializationResult {

0 commit comments

Comments
 (0)