From 4f949c91f41e25719adbfd50bb4000b9d31d76ae Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 26 May 2022 13:05:26 -0700 Subject: [PATCH] Auto update with latest AS Release v93.2.1 (#60) * Updates Package.swift with v93.2.1 release * Version 93.2.1 Co-authored-by: Firefox Sync Engineering --- Package.swift | 6 +- .../all/Generated/Metrics/Metrics.swift | 2 +- swift-source/all/Generated/fxa_client.swift | 1240 +++++----- swift-source/all/Generated/fxa_clientFFI.h | 78 +- swift-source/all/Generated/logins.swift | 768 +++--- swift-source/all/Generated/loginsFFI.h | 58 +- swift-source/all/Generated/nimbus.swift | 1065 ++++---- swift-source/all/Generated/nimbusFFI.h | 56 +- swift-source/all/Generated/places.swift | 2188 +++++++++-------- swift-source/all/Generated/placesFFI.h | 112 +- swift-source/all/Generated/push.swift | 574 ++--- swift-source/all/Generated/pushFFI.h | 26 +- swift-source/all/Generated/tabs.swift | 806 ++++++ swift-source/all/Generated/tabsFFI.h | 92 + swift-source/all/Places/Places.swift | 2 - swift-source/all/SyncUnlockInfo.swift | 4 +- swift-source/all/Tabs/Tabs.swift | 47 + swift-source/all/crashtest.swift | 209 +- swift-source/all/crashtestFFI.h | 14 +- .../focus/Generated/Metrics/Metrics.swift | 2 +- swift-source/focus/Generated/nimbus.swift | 1065 ++++---- swift-source/focus/Generated/nimbusFFI.h | 56 +- 22 files changed, 4677 insertions(+), 3793 deletions(-) create mode 100644 swift-source/all/Generated/tabs.swift create mode 100644 swift-source/all/Generated/tabsFFI.h create mode 100644 swift-source/all/Tabs/Tabs.swift diff --git a/Package.swift b/Package.swift index 8a71d136..a8b03db1 100644 --- a/Package.swift +++ b/Package.swift @@ -1,12 +1,12 @@ // swift-tools-version:5.4 import PackageDescription -let checksum = "8df6c1aeb572c5efbf792b58dbe1fc4dab31672d83be2cf41c5339ef4b1680c8" -let version = "v93.2.0" +let checksum = "ce42430c1f7150219ba4a37bd2e1565e80ec0b8befe807d5ecddc3a650a76629" +let version = "v93.2.1" let url = "https://github.com/mozilla/application-services/releases/download/\(version)/MozillaRustComponents.xcframework.zip" // Focus xcframework -let focusChecksum = "2c9fbc8086c124a9256eb921290a605ec7de5e865e3cd1af6df7779662f0683a" +let focusChecksum = "979ce87a0552c6de1e22f48a77565e8c1c8cf3779ca0f662a27e199f5c47ec3f" let focusUrl = "https://github.com/mozilla/application-services/releases/download/\(version)/FocusRustComponents.xcframework.zip" let package = Package( name: "MozillaRustComponentsSwift", diff --git a/swift-source/all/Generated/Metrics/Metrics.swift b/swift-source/all/Generated/Metrics/Metrics.swift index b8a57b4b..6068a20b 100644 --- a/swift-source/all/Generated/Metrics/Metrics.swift +++ b/swift-source/all/Generated/Metrics/Metrics.swift @@ -22,7 +22,7 @@ extension GleanMetrics { // Intentionally left private, no external user can instantiate a new global object. } - public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 5, day: 12, hour: 3, minute: 17, second: 47)) + public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 5, day: 26, hour: 15, minute: 8, second: 49)) } enum NimbusEvents { diff --git a/swift-source/all/Generated/fxa_client.swift b/swift-source/all/Generated/fxa_client.swift index 8ab73b67..a2888ed2 100644 --- a/swift-source/all/Generated/fxa_client.swift +++ b/swift-source/all/Generated/fxa_client.swift @@ -19,13 +19,13 @@ private extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_fxa_client_907c_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_fxa_client_7d70_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_fxa_client_907c_rustbuffer_free(self, $0) } + try! rustCall { ffi_fxa_client_7d70_rustbuffer_free(self, $0) } } } @@ -147,45 +147,39 @@ private class Writer { } } -// Types conforming to `Serializable` can be read and written in a bytebuffer. -private protocol Serializable { - func write(into: Writer) - static func read(from: Reader) throws -> Self -} - -// Types confirming to `ViaFfi` can be transferred back-and-for over the FFI. -// This is analogous to the Rust trait of the same name. -private protocol ViaFfi: Serializable { +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { associatedtype FfiType - static func lift(_ v: FfiType) throws -> Self - func lower() -> FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol Primitive {} - -private extension Primitive { - typealias FfiType = Self +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} - static func lift(_ v: Self) throws -> Self { - return v +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value } - func lower() -> Self { - return self + static func lower(_ value: SwiftType) -> FfiType { + return value } } -// Types conforming to `ViaFfiUsingByteBuffer` lift and lower into a bytebuffer. -// Use this for complex types where it's hard to write a custom lift/lower. -private protocol ViaFfiUsingByteBuffer: Serializable {} +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} -private extension ViaFfiUsingByteBuffer { - typealias FfiType = RustBuffer - - static func lift(_ buf: FfiType) throws -> Self { +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) + let value = try read(from: reader) if reader.hasRemaining() { throw UniffiInternalError.incompleteData } @@ -193,9 +187,9 @@ private extension ViaFfiUsingByteBuffer { return value } - func lower() -> FfiType { + static func lower(_ value: SwiftType) -> RustBuffer { let writer = Writer() - write(into: writer) + write(value, into: writer) return RustBuffer(bytes: writer.bytes) } } @@ -252,8 +246,11 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T }) } -private func rustCallWithError(_: E.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: { try E.lift($0) }) +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { @@ -271,7 +268,7 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) // with the message. But if that code panics, then it just sends back // an empty buffer. if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try String.lift(callStatus.errorBuf)) + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) } else { callStatus.errorBuf.deallocate() throw UniffiInternalError.rustPanic("Rust panic") @@ -282,103 +279,6 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -// Protocols for converters we'll implement in templates - -private protocol FfiConverter { - associatedtype SwiftType - associatedtype FfiType - - static func lift(_ ffiValue: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - - static func read(from: Reader) throws -> SwiftType - static func write(_ value: SwiftType, into: Writer) -} - -private protocol FfiConverterUsingByteBuffer: FfiConverter where FfiType == RustBuffer { - // Empty, because we want to declare some helper methods in the extension below. -} - -extension FfiConverterUsingByteBuffer { - static func lower(_ value: SwiftType) -> FfiType { - let writer = Writer() - Self.write(value, into: writer) - return RustBuffer(bytes: writer.bytes) - } - - static func lift(_ buf: FfiType) throws -> SwiftType { - let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) - if reader.hasRemaining() { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } -} - -// Helpers for structural types. Note that because of canonical_names, it /should/ be impossible -// to make another `FfiConverterSequence` etc just using the UDL. -private enum FfiConverterSequence { - static func write(_ value: [T], into buf: Writer, writeItem: (T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for item in value { - writeItem(item, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> [T] { - let len: Int32 = try buf.readInt() - var seq = [T]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try readItem(buf)) - } - return seq - } -} - -private enum FfiConverterOptional { - static func write(_ value: T?, into buf: Writer, writeItem: (T, Writer) -> Void) { - guard let value = value else { - buf.writeInt(Int8(0)) - return - } - buf.writeInt(Int8(1)) - writeItem(value, buf) - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> T? { - switch try buf.readInt() as Int8 { - case 0: return nil - case 1: return try readItem(buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -private enum FfiConverterDictionary { - static func write(_ value: [String: T], into buf: Writer, writeItem: (String, T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for (key, value) in value { - writeItem(key, value, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> (String, T)) throws -> [String: T] { - let len: Int32 = try buf.readInt() - var dict = [String: T]() - dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { - let (key, value) = try readItem(buf) - dict[key] = value - } - return dict - } -} - // Public interface members begin here. // Note that we don't yet support `indirect` for enums. @@ -393,22 +293,30 @@ public enum DeviceType { case unknown } -extension DeviceType: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> DeviceType { +private struct FfiConverterTypeDeviceType: FfiConverterRustBuffer { + typealias SwiftType = DeviceType + + static func read(from buf: Reader) throws -> DeviceType { let variant: Int32 = try buf.readInt() switch variant { case 1: return .desktop + case 2: return .mobile + case 3: return .tablet + case 4: return .vr + case 5: return .tv + case 6: return .unknown + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: DeviceType, into buf: Writer) { + switch value { case .desktop: buf.writeInt(Int32(1)) @@ -439,17 +347,20 @@ public enum DeviceCapability { case sendTab } -extension DeviceCapability: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> DeviceCapability { +private struct FfiConverterTypeDeviceCapability: FfiConverterRustBuffer { + typealias SwiftType = DeviceCapability + + static func read(from buf: Reader) throws -> DeviceCapability { let variant: Int32 = try buf.readInt() switch variant { case 1: return .sendTab + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: DeviceCapability, into buf: Writer) { + switch value { case .sendTab: buf.writeInt(Int32(1)) } @@ -470,32 +381,40 @@ public enum AccountEvent { case deviceDisconnected(deviceId: String, isLocalDevice: Bool) } -extension AccountEvent: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> AccountEvent { +private struct FfiConverterTypeAccountEvent: FfiConverterRustBuffer { + typealias SwiftType = AccountEvent + + static func read(from buf: Reader) throws -> AccountEvent { let variant: Int32 = try buf.readInt() switch variant { case 1: return .commandReceived( - command: try IncomingDeviceCommand.read(from: buf) + command: try FfiConverterTypeIncomingDeviceCommand.read(from: buf) ) + case 2: return .profileUpdated + case 3: return .accountAuthStateChanged + case 4: return .accountDestroyed + case 5: return .deviceConnected( - deviceName: try String.read(from: buf) + deviceName: try FfiConverterString.read(from: buf) ) + case 6: return .deviceDisconnected( - deviceId: try String.read(from: buf), - isLocalDevice: try Bool.read(from: buf) + deviceId: try FfiConverterString.read(from: buf), + isLocalDevice: try FfiConverterBool.read(from: buf) ) + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: AccountEvent, into buf: Writer) { + switch value { case let .commandReceived(command): buf.writeInt(Int32(1)) - command.write(into: buf) + FfiConverterTypeIncomingDeviceCommand.write(command, into: buf) case .profileUpdated: buf.writeInt(Int32(2)) @@ -508,12 +427,12 @@ extension AccountEvent: ViaFfiUsingByteBuffer, ViaFfi { case let .deviceConnected(deviceName): buf.writeInt(Int32(5)) - deviceName.write(into: buf) + FfiConverterString.write(deviceName, into: buf) case let .deviceDisconnected(deviceId, isLocalDevice): buf.writeInt(Int32(6)) - deviceId.write(into: buf) - isLocalDevice.write(into: buf) + FfiConverterString.write(deviceId, into: buf) + FfiConverterBool.write(isLocalDevice, into: buf) } } } @@ -527,24 +446,27 @@ public enum IncomingDeviceCommand { case tabReceived(sender: Device?, payload: SendTabPayload) } -extension IncomingDeviceCommand: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> IncomingDeviceCommand { +private struct FfiConverterTypeIncomingDeviceCommand: FfiConverterRustBuffer { + typealias SwiftType = IncomingDeviceCommand + + static func read(from buf: Reader) throws -> IncomingDeviceCommand { let variant: Int32 = try buf.readInt() switch variant { case 1: return .tabReceived( - sender: try FfiConverterOptionRecordDevice.read(from: buf), - payload: try SendTabPayload.read(from: buf) + sender: try FfiConverterOptionTypeDevice.read(from: buf), + payload: try FfiConverterTypeSendTabPayload.read(from: buf) ) + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: IncomingDeviceCommand, into buf: Writer) { + switch value { case let .tabReceived(sender, payload): buf.writeInt(Int32(1)) - FfiConverterOptionRecordDevice.write(sender, into: buf) - payload.write(into: buf) + FfiConverterOptionTypeDevice.write(sender, into: buf) + FfiConverterTypeSendTabPayload.write(payload, into: buf) } } } @@ -560,19 +482,24 @@ public enum MigrationState { case reuseSessionToken } -extension MigrationState: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> MigrationState { +private struct FfiConverterTypeMigrationState: FfiConverterRustBuffer { + typealias SwiftType = MigrationState + + static func read(from buf: Reader) throws -> MigrationState { let variant: Int32 = try buf.readInt() switch variant { case 1: return .none + case 2: return .copySessionToken + case 3: return .reuseSessionToken + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: MigrationState, into buf: Writer) { + switch value { case .none: buf.writeInt(Int32(1)) @@ -626,7 +553,7 @@ public class FirefoxAccount: FirefoxAccountProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer @@ -636,273 +563,334 @@ public class FirefoxAccount: FirefoxAccountProtocol { self.init(unsafeFromRawPointer: try! rustCall { - fxa_client_907c_FirefoxAccount_new(contentUrl.lower(), clientId.lower(), redirectUri.lower(), FfiConverterOptionString.lower(tokenServerUrlOverride), $0) + fxa_client_7d70_FirefoxAccount_new( + FfiConverterString.lower(contentUrl), + FfiConverterString.lower(clientId), + FfiConverterString.lower(redirectUri), + FfiConverterOptionString.lower(tokenServerUrlOverride), $0 + ) }) } deinit { - try! rustCall { ffi_fxa_client_907c_FirefoxAccount_object_free(pointer, $0) } + try! rustCall { ffi_fxa_client_7d70_FirefoxAccount_object_free(pointer, $0) } } public static func fromJson(data: String) throws -> FirefoxAccount { return FirefoxAccount(unsafeFromRawPointer: try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_from_json(data.lower(), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_from_json( + FfiConverterString.lower(data), $0 + ) }) } public func toJson() throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_to_json(self.pointer, $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_to_json(self.pointer, $0) + } + ) } public func beginOauthFlow(scopes: [String], entrypoint: String, metrics: MetricsParams?) throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_begin_oauth_flow(self.pointer, FfiConverterSequenceString.lower(scopes), entrypoint.lower(), FfiConverterOptionRecordMetricsParams.lower(metrics), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_begin_oauth_flow(self.pointer, + FfiConverterSequenceString.lower(scopes), + FfiConverterString.lower(entrypoint), + FfiConverterOptionTypeMetricsParams.lower(metrics), $0) + } + ) } public func getPairingAuthorityUrl() throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_pairing_authority_url(self.pointer, $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_pairing_authority_url(self.pointer, $0) + } + ) } public func beginPairingFlow(pairingUrl: String, scopes: [String], entrypoint: String, metrics: MetricsParams?) throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_begin_pairing_flow(self.pointer, pairingUrl.lower(), FfiConverterSequenceString.lower(scopes), entrypoint.lower(), FfiConverterOptionRecordMetricsParams.lower(metrics), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_begin_pairing_flow(self.pointer, + FfiConverterString.lower(pairingUrl), + FfiConverterSequenceString.lower(scopes), + FfiConverterString.lower(entrypoint), + FfiConverterOptionTypeMetricsParams.lower(metrics), $0) + } + ) } public func completeOauthFlow(code: String, state: String) throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_complete_oauth_flow(self.pointer, code.lower(), state.lower(), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_complete_oauth_flow(self.pointer, + FfiConverterString.lower(code), + FfiConverterString.lower(state), $0) } } public func checkAuthorizationStatus() throws -> AuthorizationInfo { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_check_authorization_status(self.pointer, $0) - } - return try AuthorizationInfo.lift(_retval) + return try FfiConverterTypeAuthorizationInfo.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_check_authorization_status(self.pointer, $0) + } + ) } public func disconnect() { try! rustCall { - fxa_client_907c_FirefoxAccount_disconnect(self.pointer, $0) + fxa_client_7d70_FirefoxAccount_disconnect(self.pointer, $0) } } public func getProfile(ignoreCache: Bool) throws -> Profile { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_profile(self.pointer, ignoreCache.lower(), $0) - } - return try Profile.lift(_retval) + return try FfiConverterTypeProfile.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_profile(self.pointer, + FfiConverterBool.lower(ignoreCache), $0) + } + ) } public func initializeDevice(name: String, deviceType: DeviceType, supportedCapabilities: [DeviceCapability]) throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_initialize_device(self.pointer, name.lower(), deviceType.lower(), FfiConverterSequenceEnumDeviceCapability.lower(supportedCapabilities), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_initialize_device(self.pointer, + FfiConverterString.lower(name), + FfiConverterTypeDeviceType.lower(deviceType), + FfiConverterSequenceTypeDeviceCapability.lower(supportedCapabilities), $0) } } public func getCurrentDeviceId() throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_current_device_id(self.pointer, $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_current_device_id(self.pointer, $0) + } + ) } public func getDevices(ignoreCache: Bool) throws -> [Device] { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_devices(self.pointer, ignoreCache.lower(), $0) - } - return try FfiConverterSequenceRecordDevice.lift(_retval) + return try FfiConverterSequenceTypeDevice.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_devices(self.pointer, + FfiConverterBool.lower(ignoreCache), $0) + } + ) } public func getAttachedClients() throws -> [AttachedClient] { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_attached_clients(self.pointer, $0) - } - return try FfiConverterSequenceRecordAttachedClient.lift(_retval) + return try FfiConverterSequenceTypeAttachedClient.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_attached_clients(self.pointer, $0) + } + ) } public func setDeviceName(displayName: String) throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_set_device_name(self.pointer, displayName.lower(), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_set_device_name(self.pointer, + FfiConverterString.lower(displayName), $0) } } public func clearDeviceName() throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_clear_device_name(self.pointer, $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_clear_device_name(self.pointer, $0) } } public func ensureCapabilities(supportedCapabilities: [DeviceCapability]) throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_ensure_capabilities(self.pointer, FfiConverterSequenceEnumDeviceCapability.lower(supportedCapabilities), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_ensure_capabilities(self.pointer, + FfiConverterSequenceTypeDeviceCapability.lower(supportedCapabilities), $0) } } public func setPushSubscription(subscription: DevicePushSubscription) throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_set_push_subscription(self.pointer, subscription.lower(), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_set_push_subscription(self.pointer, + FfiConverterTypeDevicePushSubscription.lower(subscription), $0) } } public func handlePushMessage(payload: String) throws -> [AccountEvent] { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_handle_push_message(self.pointer, payload.lower(), $0) - } - return try FfiConverterSequenceEnumAccountEvent.lift(_retval) + return try FfiConverterSequenceTypeAccountEvent.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_handle_push_message(self.pointer, + FfiConverterString.lower(payload), $0) + } + ) } public func pollDeviceCommands() throws -> [IncomingDeviceCommand] { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_poll_device_commands(self.pointer, $0) - } - return try FfiConverterSequenceEnumIncomingDeviceCommand.lift(_retval) + return try FfiConverterSequenceTypeIncomingDeviceCommand.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_poll_device_commands(self.pointer, $0) + } + ) } public func sendSingleTab(targetDeviceId: String, title: String, url: String) throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_send_single_tab(self.pointer, targetDeviceId.lower(), title.lower(), url.lower(), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_send_single_tab(self.pointer, + FfiConverterString.lower(targetDeviceId), + FfiConverterString.lower(title), + FfiConverterString.lower(url), $0) } } public func getTokenServerEndpointUrl() throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_token_server_endpoint_url(self.pointer, $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_token_server_endpoint_url(self.pointer, $0) + } + ) } public func getConnectionSuccessUrl() throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_connection_success_url(self.pointer, $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_connection_success_url(self.pointer, $0) + } + ) } public func getManageAccountUrl(entrypoint: String) throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_manage_account_url(self.pointer, entrypoint.lower(), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_manage_account_url(self.pointer, + FfiConverterString.lower(entrypoint), $0) + } + ) } public func getManageDevicesUrl(entrypoint: String) throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_manage_devices_url(self.pointer, entrypoint.lower(), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_manage_devices_url(self.pointer, + FfiConverterString.lower(entrypoint), $0) + } + ) } public func getAccessToken(scope: String, ttl: Int64?) throws -> AccessTokenInfo { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_access_token(self.pointer, scope.lower(), FfiConverterOptionInt64.lower(ttl), $0) - } - return try AccessTokenInfo.lift(_retval) + return try FfiConverterTypeAccessTokenInfo.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_access_token(self.pointer, + FfiConverterString.lower(scope), + FfiConverterOptionInt64.lower(ttl), $0) + } + ) } public func getSessionToken() throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_get_session_token(self.pointer, $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_get_session_token(self.pointer, $0) + } + ) } public func handleSessionTokenChange(sessionToken: String) throws { try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_handle_session_token_change(self.pointer, sessionToken.lower(), $0) + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_handle_session_token_change(self.pointer, + FfiConverterString.lower(sessionToken), $0) } } public func authorizeCodeUsingSessionToken(params: AuthorizationParameters) throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_authorize_code_using_session_token(self.pointer, params.lower(), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_authorize_code_using_session_token(self.pointer, + FfiConverterTypeAuthorizationParameters.lower(params), $0) + } + ) } public func clearAccessTokenCache() { try! rustCall { - fxa_client_907c_FirefoxAccount_clear_access_token_cache(self.pointer, $0) + fxa_client_7d70_FirefoxAccount_clear_access_token_cache(self.pointer, $0) } } public func gatherTelemetry() throws -> String { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_gather_telemetry(self.pointer, $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_gather_telemetry(self.pointer, $0) + } + ) } public func migrateFromSessionToken(sessionToken: String, kSync: String, kXcs: String, copySessionToken: Bool) throws -> FxAMigrationResult { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_migrate_from_session_token(self.pointer, sessionToken.lower(), kSync.lower(), kXcs.lower(), copySessionToken.lower(), $0) - } - return try FxAMigrationResult.lift(_retval) + return try FfiConverterTypeFxAMigrationResult.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_migrate_from_session_token(self.pointer, + FfiConverterString.lower(sessionToken), + FfiConverterString.lower(kSync), + FfiConverterString.lower(kXcs), + FfiConverterBool.lower(copySessionToken), $0) + } + ) } public func retryMigrateFromSessionToken() throws -> FxAMigrationResult { - let _retval = try - rustCallWithError(FxaError.self) { - fxa_client_907c_FirefoxAccount_retry_migrate_from_session_token(self.pointer, $0) - } - return try FxAMigrationResult.lift(_retval) + return try FfiConverterTypeFxAMigrationResult.lift( + try + rustCallWithError(FfiConverterTypeFxaError.self) { + fxa_client_7d70_FirefoxAccount_retry_migrate_from_session_token(self.pointer, $0) + } + ) } public func isInMigrationState() -> MigrationState { - let _retval = try! - rustCall { - fxa_client_907c_FirefoxAccount_is_in_migration_state(self.pointer, $0) - } - return try! MigrationState.lift(_retval) + return try! FfiConverterTypeMigrationState.lift( + try! + rustCall { + fxa_client_7d70_FirefoxAccount_is_in_migration_state(self.pointer, $0) + } + ) } } -private extension FirefoxAccount { +private struct FfiConverterTypeFirefoxAccount: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = FirefoxAccount - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> FirefoxAccount { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -913,27 +901,21 @@ private extension FirefoxAccount { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: FirefoxAccount, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FirefoxAccount { + return FirefoxAccount(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: FirefoxAccount) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension FirefoxAccount: ViaFfi, Serializable {} - public struct AuthorizationInfo { public var active: Bool @@ -957,20 +939,18 @@ extension AuthorizationInfo: Equatable, Hashable { } } -private extension AuthorizationInfo { - static func read(from buf: Reader) throws -> AuthorizationInfo { +private struct FfiConverterTypeAuthorizationInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AuthorizationInfo { return try AuthorizationInfo( - active: Bool.read(from: buf) + active: FfiConverterBool.read(from: buf) ) } - func write(into buf: Writer) { - active.write(into: buf) + fileprivate static func write(_ value: AuthorizationInfo, into buf: Writer) { + FfiConverterBool.write(value.active, into: buf) } } -extension AuthorizationInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct MetricsParams { public var parameters: [String: String] @@ -994,20 +974,18 @@ extension MetricsParams: Equatable, Hashable { } } -private extension MetricsParams { - static func read(from buf: Reader) throws -> MetricsParams { +private struct FfiConverterTypeMetricsParams: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> MetricsParams { return try MetricsParams( - parameters: FfiConverterDictionaryString.read(from: buf) + parameters: FfiConverterDictionaryStringString.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterDictionaryString.write(parameters, into: buf) + fileprivate static func write(_ value: MetricsParams, into buf: Writer) { + FfiConverterDictionaryStringString.write(value.parameters, into: buf) } } -extension MetricsParams: ViaFfiUsingByteBuffer, ViaFfi {} - public struct AccessTokenInfo { public var scope: String public var token: String @@ -1049,26 +1027,24 @@ extension AccessTokenInfo: Equatable, Hashable { } } -private extension AccessTokenInfo { - static func read(from buf: Reader) throws -> AccessTokenInfo { +private struct FfiConverterTypeAccessTokenInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AccessTokenInfo { return try AccessTokenInfo( - scope: String.read(from: buf), - token: String.read(from: buf), - key: FfiConverterOptionRecordScopedKey.read(from: buf), - expiresAt: Int64.read(from: buf) + scope: FfiConverterString.read(from: buf), + token: FfiConverterString.read(from: buf), + key: FfiConverterOptionTypeScopedKey.read(from: buf), + expiresAt: FfiConverterInt64.read(from: buf) ) } - func write(into buf: Writer) { - scope.write(into: buf) - token.write(into: buf) - FfiConverterOptionRecordScopedKey.write(key, into: buf) - expiresAt.write(into: buf) + fileprivate static func write(_ value: AccessTokenInfo, into buf: Writer) { + FfiConverterString.write(value.scope, into: buf) + FfiConverterString.write(value.token, into: buf) + FfiConverterOptionTypeScopedKey.write(value.key, into: buf) + FfiConverterInt64.write(value.expiresAt, into: buf) } } -extension AccessTokenInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct ScopedKey { public var kty: String public var scope: String @@ -1110,26 +1086,24 @@ extension ScopedKey: Equatable, Hashable { } } -private extension ScopedKey { - static func read(from buf: Reader) throws -> ScopedKey { +private struct FfiConverterTypeScopedKey: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> ScopedKey { return try ScopedKey( - kty: String.read(from: buf), - scope: String.read(from: buf), - k: String.read(from: buf), - kid: String.read(from: buf) + kty: FfiConverterString.read(from: buf), + scope: FfiConverterString.read(from: buf), + k: FfiConverterString.read(from: buf), + kid: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - kty.write(into: buf) - scope.write(into: buf) - k.write(into: buf) - kid.write(into: buf) + fileprivate static func write(_ value: ScopedKey, into buf: Writer) { + FfiConverterString.write(value.kty, into: buf) + FfiConverterString.write(value.scope, into: buf) + FfiConverterString.write(value.k, into: buf) + FfiConverterString.write(value.kid, into: buf) } } -extension ScopedKey: ViaFfiUsingByteBuffer, ViaFfi {} - public struct AuthorizationParameters { public var clientId: String public var scope: [String] @@ -1189,32 +1163,30 @@ extension AuthorizationParameters: Equatable, Hashable { } } -private extension AuthorizationParameters { - static func read(from buf: Reader) throws -> AuthorizationParameters { +private struct FfiConverterTypeAuthorizationParameters: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AuthorizationParameters { return try AuthorizationParameters( - clientId: String.read(from: buf), + clientId: FfiConverterString.read(from: buf), scope: FfiConverterSequenceString.read(from: buf), - state: String.read(from: buf), - accessType: String.read(from: buf), + state: FfiConverterString.read(from: buf), + accessType: FfiConverterString.read(from: buf), codeChallenge: FfiConverterOptionString.read(from: buf), codeChallengeMethod: FfiConverterOptionString.read(from: buf), keysJwk: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - clientId.write(into: buf) - FfiConverterSequenceString.write(scope, into: buf) - state.write(into: buf) - accessType.write(into: buf) - FfiConverterOptionString.write(codeChallenge, into: buf) - FfiConverterOptionString.write(codeChallengeMethod, into: buf) - FfiConverterOptionString.write(keysJwk, into: buf) + fileprivate static func write(_ value: AuthorizationParameters, into buf: Writer) { + FfiConverterString.write(value.clientId, into: buf) + FfiConverterSequenceString.write(value.scope, into: buf) + FfiConverterString.write(value.state, into: buf) + FfiConverterString.write(value.accessType, into: buf) + FfiConverterOptionString.write(value.codeChallenge, into: buf) + FfiConverterOptionString.write(value.codeChallengeMethod, into: buf) + FfiConverterOptionString.write(value.keysJwk, into: buf) } } -extension AuthorizationParameters: ViaFfiUsingByteBuffer, ViaFfi {} - public struct Device { public var id: String public var displayName: String @@ -1280,34 +1252,32 @@ extension Device: Equatable, Hashable { } } -private extension Device { - static func read(from buf: Reader) throws -> Device { +private struct FfiConverterTypeDevice: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> Device { return try Device( - id: String.read(from: buf), - displayName: String.read(from: buf), - deviceType: DeviceType.read(from: buf), - capabilities: FfiConverterSequenceEnumDeviceCapability.read(from: buf), - pushSubscription: FfiConverterOptionRecordDevicePushSubscription.read(from: buf), - pushEndpointExpired: Bool.read(from: buf), - isCurrentDevice: Bool.read(from: buf), + id: FfiConverterString.read(from: buf), + displayName: FfiConverterString.read(from: buf), + deviceType: FfiConverterTypeDeviceType.read(from: buf), + capabilities: FfiConverterSequenceTypeDeviceCapability.read(from: buf), + pushSubscription: FfiConverterOptionTypeDevicePushSubscription.read(from: buf), + pushEndpointExpired: FfiConverterBool.read(from: buf), + isCurrentDevice: FfiConverterBool.read(from: buf), lastAccessTime: FfiConverterOptionInt64.read(from: buf) ) } - func write(into buf: Writer) { - id.write(into: buf) - displayName.write(into: buf) - deviceType.write(into: buf) - FfiConverterSequenceEnumDeviceCapability.write(capabilities, into: buf) - FfiConverterOptionRecordDevicePushSubscription.write(pushSubscription, into: buf) - pushEndpointExpired.write(into: buf) - isCurrentDevice.write(into: buf) - FfiConverterOptionInt64.write(lastAccessTime, into: buf) + fileprivate static func write(_ value: Device, into buf: Writer) { + FfiConverterString.write(value.id, into: buf) + FfiConverterString.write(value.displayName, into: buf) + FfiConverterTypeDeviceType.write(value.deviceType, into: buf) + FfiConverterSequenceTypeDeviceCapability.write(value.capabilities, into: buf) + FfiConverterOptionTypeDevicePushSubscription.write(value.pushSubscription, into: buf) + FfiConverterBool.write(value.pushEndpointExpired, into: buf) + FfiConverterBool.write(value.isCurrentDevice, into: buf) + FfiConverterOptionInt64.write(value.lastAccessTime, into: buf) } } -extension Device: ViaFfiUsingByteBuffer, ViaFfi {} - public struct DevicePushSubscription { public var endpoint: String public var publicKey: String @@ -1343,24 +1313,22 @@ extension DevicePushSubscription: Equatable, Hashable { } } -private extension DevicePushSubscription { - static func read(from buf: Reader) throws -> DevicePushSubscription { +private struct FfiConverterTypeDevicePushSubscription: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> DevicePushSubscription { return try DevicePushSubscription( - endpoint: String.read(from: buf), - publicKey: String.read(from: buf), - authKey: String.read(from: buf) + endpoint: FfiConverterString.read(from: buf), + publicKey: FfiConverterString.read(from: buf), + authKey: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - endpoint.write(into: buf) - publicKey.write(into: buf) - authKey.write(into: buf) + fileprivate static func write(_ value: DevicePushSubscription, into buf: Writer) { + FfiConverterString.write(value.endpoint, into: buf) + FfiConverterString.write(value.publicKey, into: buf) + FfiConverterString.write(value.authKey, into: buf) } } -extension DevicePushSubscription: ViaFfiUsingByteBuffer, ViaFfi {} - public struct SendTabPayload { public var entries: [TabHistoryEntry] public var flowId: String @@ -1396,24 +1364,22 @@ extension SendTabPayload: Equatable, Hashable { } } -private extension SendTabPayload { - static func read(from buf: Reader) throws -> SendTabPayload { +private struct FfiConverterTypeSendTabPayload: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> SendTabPayload { return try SendTabPayload( - entries: FfiConverterSequenceRecordTabHistoryEntry.read(from: buf), - flowId: String.read(from: buf), - streamId: String.read(from: buf) + entries: FfiConverterSequenceTypeTabHistoryEntry.read(from: buf), + flowId: FfiConverterString.read(from: buf), + streamId: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterSequenceRecordTabHistoryEntry.write(entries, into: buf) - flowId.write(into: buf) - streamId.write(into: buf) + fileprivate static func write(_ value: SendTabPayload, into buf: Writer) { + FfiConverterSequenceTypeTabHistoryEntry.write(value.entries, into: buf) + FfiConverterString.write(value.flowId, into: buf) + FfiConverterString.write(value.streamId, into: buf) } } -extension SendTabPayload: ViaFfiUsingByteBuffer, ViaFfi {} - public struct TabHistoryEntry { public var title: String public var url: String @@ -1443,22 +1409,20 @@ extension TabHistoryEntry: Equatable, Hashable { } } -private extension TabHistoryEntry { - static func read(from buf: Reader) throws -> TabHistoryEntry { +private struct FfiConverterTypeTabHistoryEntry: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> TabHistoryEntry { return try TabHistoryEntry( - title: String.read(from: buf), - url: String.read(from: buf) + title: FfiConverterString.read(from: buf), + url: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - title.write(into: buf) - url.write(into: buf) + fileprivate static func write(_ value: TabHistoryEntry, into buf: Writer) { + FfiConverterString.write(value.title, into: buf) + FfiConverterString.write(value.url, into: buf) } } -extension TabHistoryEntry: ViaFfiUsingByteBuffer, ViaFfi {} - public struct AttachedClient { public var clientId: String? public var deviceId: String? @@ -1524,13 +1488,13 @@ extension AttachedClient: Equatable, Hashable { } } -private extension AttachedClient { - static func read(from buf: Reader) throws -> AttachedClient { +private struct FfiConverterTypeAttachedClient: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AttachedClient { return try AttachedClient( clientId: FfiConverterOptionString.read(from: buf), deviceId: FfiConverterOptionString.read(from: buf), - deviceType: FfiConverterOptionEnumDeviceType.read(from: buf), - isCurrentSession: Bool.read(from: buf), + deviceType: FfiConverterOptionTypeDeviceType.read(from: buf), + isCurrentSession: FfiConverterBool.read(from: buf), name: FfiConverterOptionString.read(from: buf), createdTime: FfiConverterOptionInt64.read(from: buf), lastAccessTime: FfiConverterOptionInt64.read(from: buf), @@ -1538,20 +1502,18 @@ private extension AttachedClient { ) } - func write(into buf: Writer) { - FfiConverterOptionString.write(clientId, into: buf) - FfiConverterOptionString.write(deviceId, into: buf) - FfiConverterOptionEnumDeviceType.write(deviceType, into: buf) - isCurrentSession.write(into: buf) - FfiConverterOptionString.write(name, into: buf) - FfiConverterOptionInt64.write(createdTime, into: buf) - FfiConverterOptionInt64.write(lastAccessTime, into: buf) - FfiConverterOptionSequenceString.write(scope, into: buf) + fileprivate static func write(_ value: AttachedClient, into buf: Writer) { + FfiConverterOptionString.write(value.clientId, into: buf) + FfiConverterOptionString.write(value.deviceId, into: buf) + FfiConverterOptionTypeDeviceType.write(value.deviceType, into: buf) + FfiConverterBool.write(value.isCurrentSession, into: buf) + FfiConverterOptionString.write(value.name, into: buf) + FfiConverterOptionInt64.write(value.createdTime, into: buf) + FfiConverterOptionInt64.write(value.lastAccessTime, into: buf) + FfiConverterOptionSequenceString.write(value.scope, into: buf) } } -extension AttachedClient: ViaFfiUsingByteBuffer, ViaFfi {} - public struct Profile { public var uid: String public var email: String @@ -1599,28 +1561,26 @@ extension Profile: Equatable, Hashable { } } -private extension Profile { - static func read(from buf: Reader) throws -> Profile { +private struct FfiConverterTypeProfile: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> Profile { return try Profile( - uid: String.read(from: buf), - email: String.read(from: buf), + uid: FfiConverterString.read(from: buf), + email: FfiConverterString.read(from: buf), displayName: FfiConverterOptionString.read(from: buf), - avatar: String.read(from: buf), - isDefaultAvatar: Bool.read(from: buf) + avatar: FfiConverterString.read(from: buf), + isDefaultAvatar: FfiConverterBool.read(from: buf) ) } - func write(into buf: Writer) { - uid.write(into: buf) - email.write(into: buf) - FfiConverterOptionString.write(displayName, into: buf) - avatar.write(into: buf) - isDefaultAvatar.write(into: buf) + fileprivate static func write(_ value: Profile, into buf: Writer) { + FfiConverterString.write(value.uid, into: buf) + FfiConverterString.write(value.email, into: buf) + FfiConverterOptionString.write(value.displayName, into: buf) + FfiConverterString.write(value.avatar, into: buf) + FfiConverterBool.write(value.isDefaultAvatar, into: buf) } } -extension Profile: ViaFfiUsingByteBuffer, ViaFfi {} - public struct FxAMigrationResult { public var totalDuration: Int64 @@ -1644,20 +1604,18 @@ extension FxAMigrationResult: Equatable, Hashable { } } -private extension FxAMigrationResult { - static func read(from buf: Reader) throws -> FxAMigrationResult { +private struct FfiConverterTypeFxAMigrationResult: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> FxAMigrationResult { return try FxAMigrationResult( - totalDuration: Int64.read(from: buf) + totalDuration: FfiConverterInt64.read(from: buf) ) } - func write(into buf: Writer) { - totalDuration.write(into: buf) + fileprivate static func write(_ value: FxAMigrationResult, into buf: Writer) { + FfiConverterInt64.write(value.totalDuration, into: buf) } } -extension FxAMigrationResult: ViaFfiUsingByteBuffer, ViaFfi {} - public enum FxaError { // Simple error enums only carry a message case Authentication(message: String) @@ -1678,58 +1636,60 @@ public enum FxaError { case Other(message: String) } -extension FxaError: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> FxaError { +private struct FfiConverterTypeFxaError: FfiConverterRustBuffer { + typealias SwiftType = FxaError + + static func read(from buf: Reader) throws -> FxaError { let variant: Int32 = try buf.readInt() switch variant { case 1: return .Authentication( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 2: return .Network( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 3: return .NoExistingAuthFlow( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 4: return .WrongAuthFlow( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 5: return .Panic( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 6: return .Other( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: FxaError, into buf: Writer) { + switch value { case let .Authentication(message): buf.writeInt(Int32(1)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .Network(message): buf.writeInt(Int32(2)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .NoExistingAuthFlow(message): buf.writeInt(Int32(3)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .WrongAuthFlow(message): buf.writeInt(Int32(4)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .Panic(message): buf.writeInt(Int32(5)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .Other(message): buf.writeInt(Int32(6)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) } } } @@ -1737,52 +1697,57 @@ extension FxaError: ViaFfiUsingByteBuffer, ViaFfi { extension FxaError: Equatable, Hashable {} extension FxaError: Error {} -extension Int64: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterInt64: FfiConverterPrimitive { + typealias FfiType = Int64 + typealias SwiftType = Int64 + + static func read(from buf: Reader) throws -> Int64 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int64, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Bool: ViaFfi { - fileprivate typealias FfiType = Int8 +private struct FfiConverterBool: FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool - fileprivate static func read(from buf: Reader) throws -> Self { - return try lift(buf.readInt()) + static func lift(_ value: Int8) throws -> Bool { + return value != 0 } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 } - fileprivate static func lift(_ v: FfiType) throws -> Self { - return v != 0 + static func read(from buf: Reader) throws -> Bool { + return try lift(buf.readInt()) } - fileprivate func lower() -> FfiType { - return self ? 1 : 0 + static func write(_ value: Bool, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension String: ViaFfi { - fileprivate typealias FfiType = RustBuffer +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer - fileprivate static func lift(_ v: FfiType) throws -> Self { + static func lift(_ value: RustBuffer) throws -> String { defer { - v.deallocate() + value.deallocate() } - if v.data == nil { + if value.data == nil { return String() } - let bytes = UnsafeBufferPointer(start: v.data!, count: Int(v.len)) + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) return String(bytes: bytes, encoding: String.Encoding.utf8)! } - fileprivate func lower() -> FfiType { - return utf8CString.withUnsafeBufferPointer { ptr in + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in // The swift string gives us int8_t, we want uint8_t. ptr.withMemoryRebound(to: UInt8.self) { ptr in // The swift string gives us a trailing null byte, we don't want it. @@ -1792,15 +1757,15 @@ extension String: ViaFfi { } } - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> String { let len: Int32 = try buf.readInt() return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! } - fileprivate func write(into buf: Writer) { - let len = Int32(utf8.count) + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) buf.writeInt(len) - buf.writeBytes(utf8) + buf.writeBytes(value.utf8) } } @@ -1824,261 +1789,348 @@ extension String: ViaFfi { // Helper code for MigrationState enum is found in EnumTemplate.swift // Helper code for FxaError error is found in ErrorTemplate.swift -private enum FfiConverterOptionInt64: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionInt64: FfiConverterRustBuffer { typealias SwiftType = Int64? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterInt64.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try Int64.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterInt64.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try String.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordDevice: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeDevice: FfiConverterRustBuffer { typealias SwiftType = Device? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeDevice.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try Device.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeDevice.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordDevicePushSubscription: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeDevicePushSubscription: FfiConverterRustBuffer { typealias SwiftType = DevicePushSubscription? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeDevicePushSubscription.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try DevicePushSubscription.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeDevicePushSubscription.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordMetricsParams: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeMetricsParams: FfiConverterRustBuffer { typealias SwiftType = MetricsParams? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeMetricsParams.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try MetricsParams.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeMetricsParams.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordScopedKey: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeScopedKey: FfiConverterRustBuffer { typealias SwiftType = ScopedKey? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeScopedKey.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try ScopedKey.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeScopedKey.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionEnumDeviceType: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeDeviceType: FfiConverterRustBuffer { typealias SwiftType = DeviceType? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeDeviceType.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try DeviceType.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeDeviceType.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionSequenceString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String]? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterSequenceString.write(item, into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterSequenceString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterSequenceString.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterSequenceString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterSequenceString: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterString.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try String.read(from: buf) + static func read(from buf: Reader) throws -> [String] { + let len: Int32 = try buf.readInt() + var seq = [String]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterString.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordAttachedClient: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeAttachedClient: FfiConverterRustBuffer { typealias SwiftType = [AttachedClient] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [AttachedClient], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeAttachedClient.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try AttachedClient.read(from: buf) + static func read(from buf: Reader) throws -> [AttachedClient] { + let len: Int32 = try buf.readInt() + var seq = [AttachedClient]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeAttachedClient.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordDevice: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeDevice: FfiConverterRustBuffer { typealias SwiftType = [Device] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [Device], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeDevice.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try Device.read(from: buf) + static func read(from buf: Reader) throws -> [Device] { + let len: Int32 = try buf.readInt() + var seq = [Device]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeDevice.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordTabHistoryEntry: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeTabHistoryEntry: FfiConverterRustBuffer { typealias SwiftType = [TabHistoryEntry] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [TabHistoryEntry], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeTabHistoryEntry.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try TabHistoryEntry.read(from: buf) + static func read(from buf: Reader) throws -> [TabHistoryEntry] { + let len: Int32 = try buf.readInt() + var seq = [TabHistoryEntry]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeTabHistoryEntry.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceEnumAccountEvent: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeAccountEvent: FfiConverterRustBuffer { typealias SwiftType = [AccountEvent] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [AccountEvent], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeAccountEvent.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try AccountEvent.read(from: buf) + static func read(from buf: Reader) throws -> [AccountEvent] { + let len: Int32 = try buf.readInt() + var seq = [AccountEvent]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeAccountEvent.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceEnumDeviceCapability: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeDeviceCapability: FfiConverterRustBuffer { typealias SwiftType = [DeviceCapability] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [DeviceCapability], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeDeviceCapability.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try DeviceCapability.read(from: buf) + static func read(from buf: Reader) throws -> [DeviceCapability] { + let len: Int32 = try buf.readInt() + var seq = [DeviceCapability]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeDeviceCapability.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceEnumIncomingDeviceCommand: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeIncomingDeviceCommand: FfiConverterRustBuffer { typealias SwiftType = [IncomingDeviceCommand] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [IncomingDeviceCommand], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeIncomingDeviceCommand.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try IncomingDeviceCommand.read(from: buf) + static func read(from buf: Reader) throws -> [IncomingDeviceCommand] { + let len: Int32 = try buf.readInt() + var seq = [IncomingDeviceCommand]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeIncomingDeviceCommand.read(from: buf)) } + return seq } } -private enum FfiConverterDictionaryString: FfiConverterUsingByteBuffer { - typealias SwiftType = [String: String] - - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterDictionary.write(value, into: buf) { key, value, buf in - key.write(into: buf) - value.write(into: buf) +private struct FfiConverterDictionaryStringString: FfiConverterRustBuffer { + fileprivate static func write(_ value: [String: String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for (key, value) in value { + FfiConverterString.write(key, into: buf) + FfiConverterString.write(value, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterDictionary.read(from: buf) { buf in - (try String.read(from: buf), - try String.read(from: buf)) + fileprivate static func read(from buf: Reader) throws -> [String: String] { + let len: Int32 = try buf.readInt() + var dict = [String: String]() + dict.reserveCapacity(Int(len)) + for _ in 0 ..< len { + let key = try FfiConverterString.read(from: buf) + let value = try FfiConverterString.read(from: buf) + dict[key] = value } + return dict } } diff --git a/swift-source/all/Generated/fxa_clientFFI.h b/swift-source/all/Generated/fxa_clientFFI.h index f84adc41..dfbcaac6 100644 --- a/swift-source/all/Generated/fxa_clientFFI.h +++ b/swift-source/all/Generated/fxa_clientFFI.h @@ -46,159 +46,159 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_fxa_client_907c_FirefoxAccount_object_free( +void ffi_fxa_client_7d70_FirefoxAccount_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull fxa_client_907c_FirefoxAccount_new( +void*_Nonnull fxa_client_7d70_FirefoxAccount_new( RustBuffer content_url,RustBuffer client_id,RustBuffer redirect_uri,RustBuffer token_server_url_override, RustCallStatus *_Nonnull out_status ); -void*_Nonnull fxa_client_907c_FirefoxAccount_from_json( +void*_Nonnull fxa_client_7d70_FirefoxAccount_from_json( RustBuffer data, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_to_json( +RustBuffer fxa_client_7d70_FirefoxAccount_to_json( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_begin_oauth_flow( +RustBuffer fxa_client_7d70_FirefoxAccount_begin_oauth_flow( void*_Nonnull ptr,RustBuffer scopes,RustBuffer entrypoint,RustBuffer metrics, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_pairing_authority_url( +RustBuffer fxa_client_7d70_FirefoxAccount_get_pairing_authority_url( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_begin_pairing_flow( +RustBuffer fxa_client_7d70_FirefoxAccount_begin_pairing_flow( void*_Nonnull ptr,RustBuffer pairing_url,RustBuffer scopes,RustBuffer entrypoint,RustBuffer metrics, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_complete_oauth_flow( +void fxa_client_7d70_FirefoxAccount_complete_oauth_flow( void*_Nonnull ptr,RustBuffer code,RustBuffer state, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_check_authorization_status( +RustBuffer fxa_client_7d70_FirefoxAccount_check_authorization_status( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_disconnect( +void fxa_client_7d70_FirefoxAccount_disconnect( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_profile( +RustBuffer fxa_client_7d70_FirefoxAccount_get_profile( void*_Nonnull ptr,int8_t ignore_cache, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_initialize_device( +void fxa_client_7d70_FirefoxAccount_initialize_device( void*_Nonnull ptr,RustBuffer name,RustBuffer device_type,RustBuffer supported_capabilities, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_current_device_id( +RustBuffer fxa_client_7d70_FirefoxAccount_get_current_device_id( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_devices( +RustBuffer fxa_client_7d70_FirefoxAccount_get_devices( void*_Nonnull ptr,int8_t ignore_cache, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_attached_clients( +RustBuffer fxa_client_7d70_FirefoxAccount_get_attached_clients( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_set_device_name( +void fxa_client_7d70_FirefoxAccount_set_device_name( void*_Nonnull ptr,RustBuffer display_name, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_clear_device_name( +void fxa_client_7d70_FirefoxAccount_clear_device_name( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_ensure_capabilities( +void fxa_client_7d70_FirefoxAccount_ensure_capabilities( void*_Nonnull ptr,RustBuffer supported_capabilities, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_set_push_subscription( +void fxa_client_7d70_FirefoxAccount_set_push_subscription( void*_Nonnull ptr,RustBuffer subscription, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_handle_push_message( +RustBuffer fxa_client_7d70_FirefoxAccount_handle_push_message( void*_Nonnull ptr,RustBuffer payload, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_poll_device_commands( +RustBuffer fxa_client_7d70_FirefoxAccount_poll_device_commands( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_send_single_tab( +void fxa_client_7d70_FirefoxAccount_send_single_tab( void*_Nonnull ptr,RustBuffer target_device_id,RustBuffer title,RustBuffer url, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_token_server_endpoint_url( +RustBuffer fxa_client_7d70_FirefoxAccount_get_token_server_endpoint_url( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_connection_success_url( +RustBuffer fxa_client_7d70_FirefoxAccount_get_connection_success_url( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_manage_account_url( +RustBuffer fxa_client_7d70_FirefoxAccount_get_manage_account_url( void*_Nonnull ptr,RustBuffer entrypoint, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_manage_devices_url( +RustBuffer fxa_client_7d70_FirefoxAccount_get_manage_devices_url( void*_Nonnull ptr,RustBuffer entrypoint, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_access_token( +RustBuffer fxa_client_7d70_FirefoxAccount_get_access_token( void*_Nonnull ptr,RustBuffer scope,RustBuffer ttl, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_get_session_token( +RustBuffer fxa_client_7d70_FirefoxAccount_get_session_token( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_handle_session_token_change( +void fxa_client_7d70_FirefoxAccount_handle_session_token_change( void*_Nonnull ptr,RustBuffer session_token, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_authorize_code_using_session_token( +RustBuffer fxa_client_7d70_FirefoxAccount_authorize_code_using_session_token( void*_Nonnull ptr,RustBuffer params, RustCallStatus *_Nonnull out_status ); -void fxa_client_907c_FirefoxAccount_clear_access_token_cache( +void fxa_client_7d70_FirefoxAccount_clear_access_token_cache( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_gather_telemetry( +RustBuffer fxa_client_7d70_FirefoxAccount_gather_telemetry( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_migrate_from_session_token( +RustBuffer fxa_client_7d70_FirefoxAccount_migrate_from_session_token( void*_Nonnull ptr,RustBuffer session_token,RustBuffer k_sync,RustBuffer k_xcs,int8_t copy_session_token, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_retry_migrate_from_session_token( +RustBuffer fxa_client_7d70_FirefoxAccount_retry_migrate_from_session_token( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer fxa_client_907c_FirefoxAccount_is_in_migration_state( +RustBuffer fxa_client_7d70_FirefoxAccount_is_in_migration_state( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_fxa_client_907c_rustbuffer_alloc( +RustBuffer ffi_fxa_client_7d70_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_fxa_client_907c_rustbuffer_from_bytes( +RustBuffer ffi_fxa_client_7d70_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_fxa_client_907c_rustbuffer_free( +void ffi_fxa_client_7d70_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_fxa_client_907c_rustbuffer_reserve( +RustBuffer ffi_fxa_client_7d70_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/swift-source/all/Generated/logins.swift b/swift-source/all/Generated/logins.swift index 06f30e32..81f44bd3 100644 --- a/swift-source/all/Generated/logins.swift +++ b/swift-source/all/Generated/logins.swift @@ -19,13 +19,13 @@ private extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_logins_5de8_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_logins_2894_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_logins_5de8_rustbuffer_free(self, $0) } + try! rustCall { ffi_logins_2894_rustbuffer_free(self, $0) } } } @@ -147,45 +147,39 @@ private class Writer { } } -// Types conforming to `Serializable` can be read and written in a bytebuffer. -private protocol Serializable { - func write(into: Writer) - static func read(from: Reader) throws -> Self -} - -// Types confirming to `ViaFfi` can be transferred back-and-for over the FFI. -// This is analogous to the Rust trait of the same name. -private protocol ViaFfi: Serializable { +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { associatedtype FfiType - static func lift(_ v: FfiType) throws -> Self - func lower() -> FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol Primitive {} +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} -private extension Primitive { - typealias FfiType = Self - - static func lift(_ v: Self) throws -> Self { - return v +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value } - func lower() -> Self { - return self + static func lower(_ value: SwiftType) -> FfiType { + return value } } -// Types conforming to `ViaFfiUsingByteBuffer` lift and lower into a bytebuffer. -// Use this for complex types where it's hard to write a custom lift/lower. -private protocol ViaFfiUsingByteBuffer: Serializable {} - -private extension ViaFfiUsingByteBuffer { - typealias FfiType = RustBuffer +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - static func lift(_ buf: FfiType) throws -> Self { +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) + let value = try read(from: reader) if reader.hasRemaining() { throw UniffiInternalError.incompleteData } @@ -193,9 +187,9 @@ private extension ViaFfiUsingByteBuffer { return value } - func lower() -> FfiType { + static func lower(_ value: SwiftType) -> RustBuffer { let writer = Writer() - write(into: writer) + write(value, into: writer) return RustBuffer(bytes: writer.bytes) } } @@ -252,8 +246,11 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T }) } -private func rustCallWithError(_: E.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: { try E.lift($0) }) +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { @@ -271,7 +268,7 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) // with the message. But if that code panics, then it just sends back // an empty buffer. if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try String.lift(callStatus.errorBuf)) + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) } else { callStatus.errorBuf.deallocate() throw UniffiInternalError.rustPanic("Rust panic") @@ -282,175 +279,111 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -// Protocols for converters we'll implement in templates - -private protocol FfiConverter { - associatedtype SwiftType - associatedtype FfiType - - static func lift(_ ffiValue: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - - static func read(from: Reader) throws -> SwiftType - static func write(_ value: SwiftType, into: Writer) -} - -private protocol FfiConverterUsingByteBuffer: FfiConverter where FfiType == RustBuffer { - // Empty, because we want to declare some helper methods in the extension below. -} - -extension FfiConverterUsingByteBuffer { - static func lower(_ value: SwiftType) -> FfiType { - let writer = Writer() - Self.write(value, into: writer) - return RustBuffer(bytes: writer.bytes) - } - - static func lift(_ buf: FfiType) throws -> SwiftType { - let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) - if reader.hasRemaining() { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } -} - -// Helpers for structural types. Note that because of canonical_names, it /should/ be impossible -// to make another `FfiConverterSequence` etc just using the UDL. -private enum FfiConverterSequence { - static func write(_ value: [T], into buf: Writer, writeItem: (T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for item in value { - writeItem(item, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> [T] { - let len: Int32 = try buf.readInt() - var seq = [T]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try readItem(buf)) - } - return seq - } -} - -private enum FfiConverterOptional { - static func write(_ value: T?, into buf: Writer, writeItem: (T, Writer) -> Void) { - guard let value = value else { - buf.writeInt(Int8(0)) - return - } - buf.writeInt(Int8(1)) - writeItem(value, buf) - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> T? { - switch try buf.readInt() as Int8 { - case 0: return nil - case 1: return try readItem(buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -private enum FfiConverterDictionary { - static func write(_ value: [String: T], into buf: Writer, writeItem: (String, T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for (key, value) in value { - writeItem(key, value, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> (String, T)) throws -> [String: T] { - let len: Int32 = try buf.readInt() - var dict = [String: T]() - dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { - let (key, value) = try readItem(buf) - dict[key] = value - } - return dict - } -} - // Public interface members begin here. public func createKey() throws -> String { - let _retval = try + return try FfiConverterString.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_create_key($0) - } - return try String.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_create_key($0) + } + ) } public func decryptLogin(login: EncryptedLogin, encryptionKey: String) throws -> Login { - let _retval = try + return try FfiConverterTypeLogin.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_decrypt_login(login.lower(), encryptionKey.lower(), $0) - } - return try Login.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_decrypt_login( + FfiConverterTypeEncryptedLogin.lower(login), + FfiConverterString.lower(encryptionKey), $0 + ) + } + ) } public func encryptLogin(login: Login, encryptionKey: String) throws -> EncryptedLogin { - let _retval = try + return try FfiConverterTypeEncryptedLogin.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_encrypt_login(login.lower(), encryptionKey.lower(), $0) - } - return try EncryptedLogin.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_encrypt_login( + FfiConverterTypeLogin.lower(login), + FfiConverterString.lower(encryptionKey), $0 + ) + } + ) } public func decryptFields(secFields: String, encryptionKey: String) throws -> SecureLoginFields { - let _retval = try + return try FfiConverterTypeSecureLoginFields.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_decrypt_fields(secFields.lower(), encryptionKey.lower(), $0) - } - return try SecureLoginFields.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_decrypt_fields( + FfiConverterString.lower(secFields), + FfiConverterString.lower(encryptionKey), $0 + ) + } + ) } public func encryptFields(secFields: SecureLoginFields, encryptionKey: String) throws -> String { - let _retval = try + return try FfiConverterString.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_encrypt_fields(secFields.lower(), encryptionKey.lower(), $0) - } - return try String.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_encrypt_fields( + FfiConverterTypeSecureLoginFields.lower(secFields), + FfiConverterString.lower(encryptionKey), $0 + ) + } + ) } public func createCanary(text: String, encryptionKey: String) throws -> String { - let _retval = try + return try FfiConverterString.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_create_canary(text.lower(), encryptionKey.lower(), $0) - } - return try String.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_create_canary( + FfiConverterString.lower(text), + FfiConverterString.lower(encryptionKey), $0 + ) + } + ) } public func checkCanary(canary: String, text: String, encryptionKey: String) throws -> Bool { - let _retval = try + return try FfiConverterBool.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_check_canary(canary.lower(), text.lower(), encryptionKey.lower(), $0) - } - return try Bool.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_check_canary( + FfiConverterString.lower(canary), + FfiConverterString.lower(text), + FfiConverterString.lower(encryptionKey), $0 + ) + } + ) } public func migrateLogins(path: String, newEncryptionKey: String, sqlcipherPath: String, sqlcipherKey: String, salt: String?) throws -> String { - let _retval = try + return try FfiConverterString.lift( + try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_migrate_logins(path.lower(), newEncryptionKey.lower(), sqlcipherPath.lower(), sqlcipherKey.lower(), FfiConverterOptionString.lower(salt), $0) - } - return try String.lift(_retval) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_migrate_logins( + FfiConverterString.lower(path), + FfiConverterString.lower(newEncryptionKey), + FfiConverterString.lower(sqlcipherPath), + FfiConverterString.lower(sqlcipherKey), + FfiConverterOptionString.lower(salt), $0 + ) + } + ) } public protocol LoginStoreProtocol { @@ -475,7 +408,7 @@ public class LoginStore: LoginStoreProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer @@ -484,135 +417,168 @@ public class LoginStore: LoginStoreProtocol { public convenience init(path: String) throws { self.init(unsafeFromRawPointer: try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_new(path.lower(), $0) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_new( + FfiConverterString.lower(path), $0 + ) }) } deinit { - try! rustCall { ffi_logins_5de8_LoginStore_object_free(pointer, $0) } + try! rustCall { ffi_logins_2894_LoginStore_object_free(pointer, $0) } } public func add(login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_add(self.pointer, login.lower(), encryptionKey.lower(), $0) - } - return try EncryptedLogin.lift(_retval) + return try FfiConverterTypeEncryptedLogin.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_add(self.pointer, + FfiConverterTypeLoginEntry.lower(login), + FfiConverterString.lower(encryptionKey), $0) + } + ) } public func update(id: String, login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_update(self.pointer, id.lower(), login.lower(), encryptionKey.lower(), $0) - } - return try EncryptedLogin.lift(_retval) + return try FfiConverterTypeEncryptedLogin.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_update(self.pointer, + FfiConverterString.lower(id), + FfiConverterTypeLoginEntry.lower(login), + FfiConverterString.lower(encryptionKey), $0) + } + ) } public func addOrUpdate(login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_add_or_update(self.pointer, login.lower(), encryptionKey.lower(), $0) - } - return try EncryptedLogin.lift(_retval) + return try FfiConverterTypeEncryptedLogin.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_add_or_update(self.pointer, + FfiConverterTypeLoginEntry.lower(login), + FfiConverterString.lower(encryptionKey), $0) + } + ) } public func delete(id: String) throws -> Bool { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_delete(self.pointer, id.lower(), $0) - } - return try Bool.lift(_retval) + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_delete(self.pointer, + FfiConverterString.lower(id), $0) + } + ) } public func wipe() throws { try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_wipe(self.pointer, $0) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_wipe(self.pointer, $0) } } public func wipeLocal() throws { try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_wipe_local(self.pointer, $0) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_wipe_local(self.pointer, $0) } } public func reset() throws { try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_reset(self.pointer, $0) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_reset(self.pointer, $0) } } public func touch(id: String) throws { try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_touch(self.pointer, id.lower(), $0) + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_touch(self.pointer, + FfiConverterString.lower(id), $0) } } public func list() throws -> [EncryptedLogin] { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_list(self.pointer, $0) - } - return try FfiConverterSequenceRecordEncryptedLogin.lift(_retval) + return try FfiConverterSequenceTypeEncryptedLogin.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_list(self.pointer, $0) + } + ) } public func getByBaseDomain(baseDomain: String) throws -> [EncryptedLogin] { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_get_by_base_domain(self.pointer, baseDomain.lower(), $0) - } - return try FfiConverterSequenceRecordEncryptedLogin.lift(_retval) + return try FfiConverterSequenceTypeEncryptedLogin.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_get_by_base_domain(self.pointer, + FfiConverterString.lower(baseDomain), $0) + } + ) } public func findLoginToUpdate(look: LoginEntry, encryptionKey: String) throws -> Login? { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_find_login_to_update(self.pointer, look.lower(), encryptionKey.lower(), $0) - } - return try FfiConverterOptionRecordLogin.lift(_retval) + return try FfiConverterOptionTypeLogin.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_find_login_to_update(self.pointer, + FfiConverterTypeLoginEntry.lower(look), + FfiConverterString.lower(encryptionKey), $0) + } + ) } public func get(id: String) throws -> EncryptedLogin? { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_get(self.pointer, id.lower(), $0) - } - return try FfiConverterOptionRecordEncryptedLogin.lift(_retval) + return try FfiConverterOptionTypeEncryptedLogin.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_get(self.pointer, + FfiConverterString.lower(id), $0) + } + ) } public func importMultiple(login: [Login], encryptionKey: String) throws -> String { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_import_multiple(self.pointer, FfiConverterSequenceRecordLogin.lower(login), encryptionKey.lower(), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_import_multiple(self.pointer, + FfiConverterSequenceTypeLogin.lower(login), + FfiConverterString.lower(encryptionKey), $0) + } + ) } public func registerWithSyncManager() { try! rustCall { - logins_5de8_LoginStore_register_with_sync_manager(self.pointer, $0) + logins_2894_LoginStore_register_with_sync_manager(self.pointer, $0) } } public func sync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String, localEncryptionKey: String) throws -> String { - let _retval = try - rustCallWithError(LoginsStorageError.self) { - logins_5de8_LoginStore_sync(self.pointer, keyId.lower(), accessToken.lower(), syncKey.lower(), tokenserverUrl.lower(), localEncryptionKey.lower(), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeLoginsStorageError.self) { + logins_2894_LoginStore_sync(self.pointer, + FfiConverterString.lower(keyId), + FfiConverterString.lower(accessToken), + FfiConverterString.lower(syncKey), + FfiConverterString.lower(tokenserverUrl), + FfiConverterString.lower(localEncryptionKey), $0) + } + ) } } -private extension LoginStore { +private struct FfiConverterTypeLoginStore: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = LoginStore - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> LoginStore { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -623,27 +589,21 @@ private extension LoginStore { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: LoginStore, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> LoginStore { + return LoginStore(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: LoginStore) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension LoginStore: ViaFfi, Serializable {} - public struct LoginFields { public var origin: String public var httpRealm: String? @@ -691,28 +651,26 @@ extension LoginFields: Equatable, Hashable { } } -private extension LoginFields { - static func read(from buf: Reader) throws -> LoginFields { +private struct FfiConverterTypeLoginFields: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> LoginFields { return try LoginFields( - origin: String.read(from: buf), + origin: FfiConverterString.read(from: buf), httpRealm: FfiConverterOptionString.read(from: buf), formActionOrigin: FfiConverterOptionString.read(from: buf), - usernameField: String.read(from: buf), - passwordField: String.read(from: buf) + usernameField: FfiConverterString.read(from: buf), + passwordField: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - origin.write(into: buf) - FfiConverterOptionString.write(httpRealm, into: buf) - FfiConverterOptionString.write(formActionOrigin, into: buf) - usernameField.write(into: buf) - passwordField.write(into: buf) + fileprivate static func write(_ value: LoginFields, into buf: Writer) { + FfiConverterString.write(value.origin, into: buf) + FfiConverterOptionString.write(value.httpRealm, into: buf) + FfiConverterOptionString.write(value.formActionOrigin, into: buf) + FfiConverterString.write(value.usernameField, into: buf) + FfiConverterString.write(value.passwordField, into: buf) } } -extension LoginFields: ViaFfiUsingByteBuffer, ViaFfi {} - public struct SecureLoginFields { public var password: String public var username: String @@ -742,22 +700,20 @@ extension SecureLoginFields: Equatable, Hashable { } } -private extension SecureLoginFields { - static func read(from buf: Reader) throws -> SecureLoginFields { +private struct FfiConverterTypeSecureLoginFields: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> SecureLoginFields { return try SecureLoginFields( - password: String.read(from: buf), - username: String.read(from: buf) + password: FfiConverterString.read(from: buf), + username: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - password.write(into: buf) - username.write(into: buf) + fileprivate static func write(_ value: SecureLoginFields, into buf: Writer) { + FfiConverterString.write(value.password, into: buf) + FfiConverterString.write(value.username, into: buf) } } -extension SecureLoginFields: ViaFfiUsingByteBuffer, ViaFfi {} - public struct RecordFields { public var id: String public var timesUsed: Int64 @@ -805,28 +761,26 @@ extension RecordFields: Equatable, Hashable { } } -private extension RecordFields { - static func read(from buf: Reader) throws -> RecordFields { +private struct FfiConverterTypeRecordFields: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> RecordFields { return try RecordFields( - id: String.read(from: buf), - timesUsed: Int64.read(from: buf), - timeCreated: Int64.read(from: buf), - timeLastUsed: Int64.read(from: buf), - timePasswordChanged: Int64.read(from: buf) + id: FfiConverterString.read(from: buf), + timesUsed: FfiConverterInt64.read(from: buf), + timeCreated: FfiConverterInt64.read(from: buf), + timeLastUsed: FfiConverterInt64.read(from: buf), + timePasswordChanged: FfiConverterInt64.read(from: buf) ) } - func write(into buf: Writer) { - id.write(into: buf) - timesUsed.write(into: buf) - timeCreated.write(into: buf) - timeLastUsed.write(into: buf) - timePasswordChanged.write(into: buf) + fileprivate static func write(_ value: RecordFields, into buf: Writer) { + FfiConverterString.write(value.id, into: buf) + FfiConverterInt64.write(value.timesUsed, into: buf) + FfiConverterInt64.write(value.timeCreated, into: buf) + FfiConverterInt64.write(value.timeLastUsed, into: buf) + FfiConverterInt64.write(value.timePasswordChanged, into: buf) } } -extension RecordFields: ViaFfiUsingByteBuffer, ViaFfi {} - public struct LoginEntry { public var fields: LoginFields public var secFields: SecureLoginFields @@ -856,22 +810,20 @@ extension LoginEntry: Equatable, Hashable { } } -private extension LoginEntry { - static func read(from buf: Reader) throws -> LoginEntry { +private struct FfiConverterTypeLoginEntry: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> LoginEntry { return try LoginEntry( - fields: LoginFields.read(from: buf), - secFields: SecureLoginFields.read(from: buf) + fields: FfiConverterTypeLoginFields.read(from: buf), + secFields: FfiConverterTypeSecureLoginFields.read(from: buf) ) } - func write(into buf: Writer) { - fields.write(into: buf) - secFields.write(into: buf) + fileprivate static func write(_ value: LoginEntry, into buf: Writer) { + FfiConverterTypeLoginFields.write(value.fields, into: buf) + FfiConverterTypeSecureLoginFields.write(value.secFields, into: buf) } } -extension LoginEntry: ViaFfiUsingByteBuffer, ViaFfi {} - public struct Login { public var record: RecordFields public var fields: LoginFields @@ -907,24 +859,22 @@ extension Login: Equatable, Hashable { } } -private extension Login { - static func read(from buf: Reader) throws -> Login { +private struct FfiConverterTypeLogin: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> Login { return try Login( - record: RecordFields.read(from: buf), - fields: LoginFields.read(from: buf), - secFields: SecureLoginFields.read(from: buf) + record: FfiConverterTypeRecordFields.read(from: buf), + fields: FfiConverterTypeLoginFields.read(from: buf), + secFields: FfiConverterTypeSecureLoginFields.read(from: buf) ) } - func write(into buf: Writer) { - record.write(into: buf) - fields.write(into: buf) - secFields.write(into: buf) + fileprivate static func write(_ value: Login, into buf: Writer) { + FfiConverterTypeRecordFields.write(value.record, into: buf) + FfiConverterTypeLoginFields.write(value.fields, into: buf) + FfiConverterTypeSecureLoginFields.write(value.secFields, into: buf) } } -extension Login: ViaFfiUsingByteBuffer, ViaFfi {} - public struct EncryptedLogin { public var record: RecordFields public var fields: LoginFields @@ -960,24 +910,22 @@ extension EncryptedLogin: Equatable, Hashable { } } -private extension EncryptedLogin { - static func read(from buf: Reader) throws -> EncryptedLogin { +private struct FfiConverterTypeEncryptedLogin: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> EncryptedLogin { return try EncryptedLogin( - record: RecordFields.read(from: buf), - fields: LoginFields.read(from: buf), - secFields: String.read(from: buf) + record: FfiConverterTypeRecordFields.read(from: buf), + fields: FfiConverterTypeLoginFields.read(from: buf), + secFields: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - record.write(into: buf) - fields.write(into: buf) - secFields.write(into: buf) + fileprivate static func write(_ value: EncryptedLogin, into buf: Writer) { + FfiConverterTypeRecordFields.write(value.record, into: buf) + FfiConverterTypeLoginFields.write(value.fields, into: buf) + FfiConverterString.write(value.secFields, into: buf) } } -extension EncryptedLogin: ViaFfiUsingByteBuffer, ViaFfi {} - public enum LoginsStorageError { // Simple error enums only carry a message case UnexpectedLoginsStorageError(message: String) @@ -1007,79 +955,81 @@ public enum LoginsStorageError { case Interrupted(message: String) } -extension LoginsStorageError: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> LoginsStorageError { +private struct FfiConverterTypeLoginsStorageError: FfiConverterRustBuffer { + typealias SwiftType = LoginsStorageError + + static func read(from buf: Reader) throws -> LoginsStorageError { let variant: Int32 = try buf.readInt() switch variant { case 1: return .UnexpectedLoginsStorageError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 2: return .SyncAuthInvalid( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 3: return .MismatchedLock( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 4: return .NoSuchRecord( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 5: return .InvalidRecord( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 6: return .CryptoError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 7: return .InvalidKey( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 8: return .RequestFailed( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 9: return .Interrupted( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: LoginsStorageError, into buf: Writer) { + switch value { case let .UnexpectedLoginsStorageError(message): buf.writeInt(Int32(1)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .SyncAuthInvalid(message): buf.writeInt(Int32(2)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .MismatchedLock(message): buf.writeInt(Int32(3)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .NoSuchRecord(message): buf.writeInt(Int32(4)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidRecord(message): buf.writeInt(Int32(5)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .CryptoError(message): buf.writeInt(Int32(6)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidKey(message): buf.writeInt(Int32(7)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .RequestFailed(message): buf.writeInt(Int32(8)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .Interrupted(message): buf.writeInt(Int32(9)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) } } } @@ -1087,52 +1037,57 @@ extension LoginsStorageError: ViaFfiUsingByteBuffer, ViaFfi { extension LoginsStorageError: Equatable, Hashable {} extension LoginsStorageError: Error {} -extension Int64: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterInt64: FfiConverterPrimitive { + typealias FfiType = Int64 + typealias SwiftType = Int64 + + static func read(from buf: Reader) throws -> Int64 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int64, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Bool: ViaFfi { - fileprivate typealias FfiType = Int8 +private struct FfiConverterBool: FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool - fileprivate static func read(from buf: Reader) throws -> Self { - return try lift(buf.readInt()) + static func lift(_ value: Int8) throws -> Bool { + return value != 0 } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 } - fileprivate static func lift(_ v: FfiType) throws -> Self { - return v != 0 + static func read(from buf: Reader) throws -> Bool { + return try lift(buf.readInt()) } - fileprivate func lower() -> FfiType { - return self ? 1 : 0 + static func write(_ value: Bool, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension String: ViaFfi { - fileprivate typealias FfiType = RustBuffer +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer - fileprivate static func lift(_ v: FfiType) throws -> Self { + static func lift(_ value: RustBuffer) throws -> String { defer { - v.deallocate() + value.deallocate() } - if v.data == nil { + if value.data == nil { return String() } - let bytes = UnsafeBufferPointer(start: v.data!, count: Int(v.len)) + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) return String(bytes: bytes, encoding: String.Encoding.utf8)! } - fileprivate func lower() -> FfiType { - return utf8CString.withUnsafeBufferPointer { ptr in + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in // The swift string gives us int8_t, we want uint8_t. ptr.withMemoryRebound(to: UInt8.self) { ptr in // The swift string gives us a trailing null byte, we don't want it. @@ -1142,15 +1097,15 @@ extension String: ViaFfi { } } - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> String { let len: Int32 = try buf.readInt() return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! } - fileprivate func write(into buf: Writer) { - let len = Int32(utf8.count) + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) buf.writeInt(len) - buf.writeBytes(utf8) + buf.writeBytes(value.utf8) } } @@ -1163,83 +1118,110 @@ extension String: ViaFfi { // Helper code for SecureLoginFields record is found in RecordTemplate.swift // Helper code for LoginsStorageError error is found in ErrorTemplate.swift -private enum FfiConverterOptionString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try String.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordEncryptedLogin: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeEncryptedLogin: FfiConverterRustBuffer { typealias SwiftType = EncryptedLogin? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeEncryptedLogin.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try EncryptedLogin.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeEncryptedLogin.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordLogin: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeLogin: FfiConverterRustBuffer { typealias SwiftType = Login? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeLogin.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try Login.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeLogin.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterSequenceRecordEncryptedLogin: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeEncryptedLogin: FfiConverterRustBuffer { typealias SwiftType = [EncryptedLogin] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [EncryptedLogin], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeEncryptedLogin.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try EncryptedLogin.read(from: buf) + static func read(from buf: Reader) throws -> [EncryptedLogin] { + let len: Int32 = try buf.readInt() + var seq = [EncryptedLogin]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeEncryptedLogin.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordLogin: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeLogin: FfiConverterRustBuffer { typealias SwiftType = [Login] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [Login], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeLogin.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try Login.read(from: buf) + static func read(from buf: Reader) throws -> [Login] { + let len: Int32 = try buf.readInt() + var seq = [Login]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeLogin.read(from: buf)) } + return seq } } diff --git a/swift-source/all/Generated/loginsFFI.h b/swift-source/all/Generated/loginsFFI.h index 506794f1..541b061d 100644 --- a/swift-source/all/Generated/loginsFFI.h +++ b/swift-source/all/Generated/loginsFFI.h @@ -46,119 +46,119 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_logins_5de8_LoginStore_object_free( +void ffi_logins_2894_LoginStore_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull logins_5de8_LoginStore_new( +void*_Nonnull logins_2894_LoginStore_new( RustBuffer path, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_add( +RustBuffer logins_2894_LoginStore_add( void*_Nonnull ptr,RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_update( +RustBuffer logins_2894_LoginStore_update( void*_Nonnull ptr,RustBuffer id,RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_add_or_update( +RustBuffer logins_2894_LoginStore_add_or_update( void*_Nonnull ptr,RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -int8_t logins_5de8_LoginStore_delete( +int8_t logins_2894_LoginStore_delete( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -void logins_5de8_LoginStore_wipe( +void logins_2894_LoginStore_wipe( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void logins_5de8_LoginStore_wipe_local( +void logins_2894_LoginStore_wipe_local( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void logins_5de8_LoginStore_reset( +void logins_2894_LoginStore_reset( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void logins_5de8_LoginStore_touch( +void logins_2894_LoginStore_touch( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_list( +RustBuffer logins_2894_LoginStore_list( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_get_by_base_domain( +RustBuffer logins_2894_LoginStore_get_by_base_domain( void*_Nonnull ptr,RustBuffer base_domain, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_find_login_to_update( +RustBuffer logins_2894_LoginStore_find_login_to_update( void*_Nonnull ptr,RustBuffer look,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_get( +RustBuffer logins_2894_LoginStore_get( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_import_multiple( +RustBuffer logins_2894_LoginStore_import_multiple( void*_Nonnull ptr,RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -void logins_5de8_LoginStore_register_with_sync_manager( +void logins_2894_LoginStore_register_with_sync_manager( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_LoginStore_sync( +RustBuffer logins_2894_LoginStore_sync( void*_Nonnull ptr,RustBuffer key_id,RustBuffer access_token,RustBuffer sync_key,RustBuffer tokenserver_url,RustBuffer local_encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_create_key( +RustBuffer logins_2894_create_key( RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_decrypt_login( +RustBuffer logins_2894_decrypt_login( RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_encrypt_login( +RustBuffer logins_2894_encrypt_login( RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_decrypt_fields( +RustBuffer logins_2894_decrypt_fields( RustBuffer sec_fields,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_encrypt_fields( +RustBuffer logins_2894_encrypt_fields( RustBuffer sec_fields,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_create_canary( +RustBuffer logins_2894_create_canary( RustBuffer text,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -int8_t logins_5de8_check_canary( +int8_t logins_2894_check_canary( RustBuffer canary,RustBuffer text,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_5de8_migrate_logins( +RustBuffer logins_2894_migrate_logins( RustBuffer path,RustBuffer new_encryption_key,RustBuffer sqlcipher_path,RustBuffer sqlcipher_key,RustBuffer salt, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_logins_5de8_rustbuffer_alloc( +RustBuffer ffi_logins_2894_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_logins_5de8_rustbuffer_from_bytes( +RustBuffer ffi_logins_2894_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_logins_5de8_rustbuffer_free( +void ffi_logins_2894_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_logins_5de8_rustbuffer_reserve( +RustBuffer ffi_logins_2894_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/swift-source/all/Generated/nimbus.swift b/swift-source/all/Generated/nimbus.swift index 07341853..c12a5603 100644 --- a/swift-source/all/Generated/nimbus.swift +++ b/swift-source/all/Generated/nimbus.swift @@ -19,13 +19,13 @@ private extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_nimbus_302d_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_nimbus_e97_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_nimbus_302d_rustbuffer_free(self, $0) } + try! rustCall { ffi_nimbus_e97_rustbuffer_free(self, $0) } } } @@ -147,45 +147,39 @@ private class Writer { } } -// Types conforming to `Serializable` can be read and written in a bytebuffer. -private protocol Serializable { - func write(into: Writer) - static func read(from: Reader) throws -> Self -} - -// Types confirming to `ViaFfi` can be transferred back-and-for over the FFI. -// This is analogous to the Rust trait of the same name. -private protocol ViaFfi: Serializable { +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { associatedtype FfiType - static func lift(_ v: FfiType) throws -> Self - func lower() -> FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol Primitive {} +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} -private extension Primitive { - typealias FfiType = Self - - static func lift(_ v: Self) throws -> Self { - return v +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value } - func lower() -> Self { - return self + static func lower(_ value: SwiftType) -> FfiType { + return value } } -// Types conforming to `ViaFfiUsingByteBuffer` lift and lower into a bytebuffer. -// Use this for complex types where it's hard to write a custom lift/lower. -private protocol ViaFfiUsingByteBuffer: Serializable {} - -private extension ViaFfiUsingByteBuffer { - typealias FfiType = RustBuffer +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - static func lift(_ buf: FfiType) throws -> Self { +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) + let value = try read(from: reader) if reader.hasRemaining() { throw UniffiInternalError.incompleteData } @@ -193,9 +187,9 @@ private extension ViaFfiUsingByteBuffer { return value } - func lower() -> FfiType { + static func lower(_ value: SwiftType) -> RustBuffer { let writer = Writer() - write(into: writer) + write(value, into: writer) return RustBuffer(bytes: writer.bytes) } } @@ -252,8 +246,11 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T }) } -private func rustCallWithError(_: E.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: { try E.lift($0) }) +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { @@ -271,7 +268,7 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) // with the message. But if that code panics, then it just sends back // an empty buffer. if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try String.lift(callStatus.errorBuf)) + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) } else { callStatus.errorBuf.deallocate() throw UniffiInternalError.rustPanic("Rust panic") @@ -282,103 +279,6 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -// Protocols for converters we'll implement in templates - -private protocol FfiConverter { - associatedtype SwiftType - associatedtype FfiType - - static func lift(_ ffiValue: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - - static func read(from: Reader) throws -> SwiftType - static func write(_ value: SwiftType, into: Writer) -} - -private protocol FfiConverterUsingByteBuffer: FfiConverter where FfiType == RustBuffer { - // Empty, because we want to declare some helper methods in the extension below. -} - -extension FfiConverterUsingByteBuffer { - static func lower(_ value: SwiftType) -> FfiType { - let writer = Writer() - Self.write(value, into: writer) - return RustBuffer(bytes: writer.bytes) - } - - static func lift(_ buf: FfiType) throws -> SwiftType { - let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) - if reader.hasRemaining() { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } -} - -// Helpers for structural types. Note that because of canonical_names, it /should/ be impossible -// to make another `FfiConverterSequence` etc just using the UDL. -private enum FfiConverterSequence { - static func write(_ value: [T], into buf: Writer, writeItem: (T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for item in value { - writeItem(item, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> [T] { - let len: Int32 = try buf.readInt() - var seq = [T]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try readItem(buf)) - } - return seq - } -} - -private enum FfiConverterOptional { - static func write(_ value: T?, into buf: Writer, writeItem: (T, Writer) -> Void) { - guard let value = value else { - buf.writeInt(Int8(0)) - return - } - buf.writeInt(Int8(1)) - writeItem(value, buf) - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> T? { - switch try buf.readInt() as Int8 { - case 0: return nil - case 1: return try readItem(buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -private enum FfiConverterDictionary { - static func write(_ value: [String: T], into buf: Writer, writeItem: (String, T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for (key, value) in value { - writeItem(key, value, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> (String, T)) throws -> [String: T] { - let len: Int32 = try buf.readInt() - var dict = [String: T]() - dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { - let (key, value) = try readItem(buf) - dict[key] = value - } - return dict - } -} - // Public interface members begin here. // Note that we don't yet support `indirect` for enums. @@ -390,19 +290,24 @@ public enum EnrollmentChangeEventType { case unenrollment } -extension EnrollmentChangeEventType: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> EnrollmentChangeEventType { +private struct FfiConverterTypeEnrollmentChangeEventType: FfiConverterRustBuffer { + typealias SwiftType = EnrollmentChangeEventType + + static func read(from buf: Reader) throws -> EnrollmentChangeEventType { let variant: Int32 = try buf.readInt() switch variant { case 1: return .enrollment + case 2: return .disqualification + case 3: return .unenrollment + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: EnrollmentChangeEventType, into buf: Writer) { + switch value { case .enrollment: buf.writeInt(Int32(1)) @@ -433,15 +338,15 @@ public protocol NimbusClientProtocol { func optInWithBranch(experimentSlug: String, branch: String) throws -> [EnrollmentChangeEvent] func optOut(experimentSlug: String) throws -> [EnrollmentChangeEvent] func resetTelemetryIdentifiers(newRandomizationUnits: AvailableRandomizationUnits) throws -> [EnrollmentChangeEvent] - func createTargetingHelper(additionalContext: String?) throws -> NimbusTargetingHelper - func createStringHelper(additionalContext: String?) throws -> NimbusStringHelper + func createTargetingHelper(additionalContext: JsonObject?) throws -> NimbusTargetingHelper + func createStringHelper(additionalContext: JsonObject?) throws -> NimbusStringHelper } public class NimbusClient: NimbusClientProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer @@ -450,153 +355,184 @@ public class NimbusClient: NimbusClientProtocol { public convenience init(appCtx: AppContext, dbpath: String, remoteSettingsConfig: RemoteSettingsConfig?, availableRandomizationUnits: AvailableRandomizationUnits) throws { self.init(unsafeFromRawPointer: try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_new(appCtx.lower(), dbpath.lower(), FfiConverterOptionRecordRemoteSettingsConfig.lower(remoteSettingsConfig), availableRandomizationUnits.lower(), $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_new( + FfiConverterTypeAppContext.lower(appCtx), + FfiConverterString.lower(dbpath), + FfiConverterOptionTypeRemoteSettingsConfig.lower(remoteSettingsConfig), + FfiConverterTypeAvailableRandomizationUnits.lower(availableRandomizationUnits), $0 + ) }) } deinit { - try! rustCall { ffi_nimbus_302d_NimbusClient_object_free(pointer, $0) } + try! rustCall { ffi_nimbus_e97_NimbusClient_object_free(pointer, $0) } } public func initialize() throws { try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_initialize(self.pointer, $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_initialize(self.pointer, $0) } } public func getExperimentBranch(id: String) throws -> String? { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_experiment_branch(self.pointer, id.lower(), $0) - } - return try FfiConverterOptionString.lift(_retval) + return try FfiConverterOptionString.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_experiment_branch(self.pointer, + FfiConverterString.lower(id), $0) + } + ) } public func getFeatureConfigVariables(featureId: String) throws -> String? { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_feature_config_variables(self.pointer, featureId.lower(), $0) - } - return try FfiConverterOptionString.lift(_retval) + return try FfiConverterOptionString.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_feature_config_variables(self.pointer, + FfiConverterString.lower(featureId), $0) + } + ) } public func getExperimentBranches(experimentSlug: String) throws -> [ExperimentBranch] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_experiment_branches(self.pointer, experimentSlug.lower(), $0) - } - return try FfiConverterSequenceRecordExperimentBranch.lift(_retval) + return try FfiConverterSequenceTypeExperimentBranch.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_experiment_branches(self.pointer, + FfiConverterString.lower(experimentSlug), $0) + } + ) } public func getActiveExperiments() throws -> [EnrolledExperiment] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_active_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordEnrolledExperiment.lift(_retval) + return try FfiConverterSequenceTypeEnrolledExperiment.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_active_experiments(self.pointer, $0) + } + ) } public func getAvailableExperiments() throws -> [AvailableExperiment] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_available_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordAvailableExperiment.lift(_retval) + return try FfiConverterSequenceTypeAvailableExperiment.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_available_experiments(self.pointer, $0) + } + ) } public func getGlobalUserParticipation() throws -> Bool { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_global_user_participation(self.pointer, $0) - } - return try Bool.lift(_retval) + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_global_user_participation(self.pointer, $0) + } + ) } public func setGlobalUserParticipation(optIn: Bool) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_set_global_user_participation(self.pointer, optIn.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_set_global_user_participation(self.pointer, + FfiConverterBool.lower(optIn), $0) + } + ) } public func updateExperiments() throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_update_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_update_experiments(self.pointer, $0) + } + ) } public func fetchExperiments() throws { try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_fetch_experiments(self.pointer, $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_fetch_experiments(self.pointer, $0) } } public func applyPendingExperiments() throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_apply_pending_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_apply_pending_experiments(self.pointer, $0) + } + ) } public func setExperimentsLocally(experimentsJson: String) throws { try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_set_experiments_locally(self.pointer, experimentsJson.lower(), $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_set_experiments_locally(self.pointer, + FfiConverterString.lower(experimentsJson), $0) } } public func optInWithBranch(experimentSlug: String, branch: String) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_opt_in_with_branch(self.pointer, experimentSlug.lower(), branch.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_opt_in_with_branch(self.pointer, + FfiConverterString.lower(experimentSlug), + FfiConverterString.lower(branch), $0) + } + ) } public func optOut(experimentSlug: String) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_opt_out(self.pointer, experimentSlug.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_opt_out(self.pointer, + FfiConverterString.lower(experimentSlug), $0) + } + ) } public func resetTelemetryIdentifiers(newRandomizationUnits: AvailableRandomizationUnits) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_reset_telemetry_identifiers(self.pointer, newRandomizationUnits.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_reset_telemetry_identifiers(self.pointer, + FfiConverterTypeAvailableRandomizationUnits.lower(newRandomizationUnits), $0) + } + ) } - public func createTargetingHelper(additionalContext: String? = nil) throws -> NimbusTargetingHelper { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_create_targeting_helper(self.pointer, FfiConverterOptionJsonObject.lower(additionalContext), $0) - } - return try NimbusTargetingHelper.lift(_retval) + public func createTargetingHelper(additionalContext: JsonObject? = nil) throws -> NimbusTargetingHelper { + return try FfiConverterTypeNimbusTargetingHelper.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_create_targeting_helper(self.pointer, + FfiConverterOptionTypeJsonObject.lower(additionalContext), $0) + } + ) } - public func createStringHelper(additionalContext: String? = nil) throws -> NimbusStringHelper { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_create_string_helper(self.pointer, FfiConverterOptionJsonObject.lower(additionalContext), $0) - } - return try NimbusStringHelper.lift(_retval) + public func createStringHelper(additionalContext: JsonObject? = nil) throws -> NimbusStringHelper { + return try FfiConverterTypeNimbusStringHelper.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_create_string_helper(self.pointer, + FfiConverterOptionTypeJsonObject.lower(additionalContext), $0) + } + ) } } -private extension NimbusClient { +private struct FfiConverterTypeNimbusClient: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = NimbusClient - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> NimbusClient { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -607,27 +543,21 @@ private extension NimbusClient { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: NimbusClient, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NimbusClient { + return NimbusClient(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: NimbusClient) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension NimbusClient: ViaFfi, Serializable {} - public protocol NimbusTargetingHelperProtocol { func evalJexl(expression: String) throws -> Bool } @@ -636,29 +566,32 @@ public class NimbusTargetingHelper: NimbusTargetingHelperProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { - try! rustCall { ffi_nimbus_302d_NimbusTargetingHelper_object_free(pointer, $0) } + try! rustCall { ffi_nimbus_e97_NimbusTargetingHelper_object_free(pointer, $0) } } public func evalJexl(expression: String) throws -> Bool { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusTargetingHelper_eval_jexl(self.pointer, expression.lower(), $0) - } - return try Bool.lift(_retval) + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusTargetingHelper_eval_jexl(self.pointer, + FfiConverterString.lower(expression), $0) + } + ) } } -private extension NimbusTargetingHelper { +private struct FfiConverterTypeNimbusTargetingHelper: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = NimbusTargetingHelper - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> NimbusTargetingHelper { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -669,27 +602,21 @@ private extension NimbusTargetingHelper { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: NimbusTargetingHelper, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NimbusTargetingHelper { + return NimbusTargetingHelper(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: NimbusTargetingHelper) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension NimbusTargetingHelper: ViaFfi, Serializable {} - public protocol NimbusStringHelperProtocol { func stringFormat(template: String, uuid: String?) -> String func getUuid(template: String) -> String? @@ -699,37 +626,43 @@ public class NimbusStringHelper: NimbusStringHelperProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { - try! rustCall { ffi_nimbus_302d_NimbusStringHelper_object_free(pointer, $0) } + try! rustCall { ffi_nimbus_e97_NimbusStringHelper_object_free(pointer, $0) } } public func stringFormat(template: String, uuid: String? = nil) -> String { - let _retval = try! - rustCall { - nimbus_302d_NimbusStringHelper_string_format(self.pointer, template.lower(), FfiConverterOptionString.lower(uuid), $0) - } - return try! String.lift(_retval) + return try! FfiConverterString.lift( + try! + rustCall { + nimbus_e97_NimbusStringHelper_string_format(self.pointer, + FfiConverterString.lower(template), + FfiConverterOptionString.lower(uuid), $0) + } + ) } public func getUuid(template: String) -> String? { - let _retval = try! - rustCall { - nimbus_302d_NimbusStringHelper_get_uuid(self.pointer, template.lower(), $0) - } - return try! FfiConverterOptionString.lift(_retval) + return try! FfiConverterOptionString.lift( + try! + rustCall { + nimbus_e97_NimbusStringHelper_get_uuid(self.pointer, + FfiConverterString.lower(template), $0) + } + ) } } -private extension NimbusStringHelper { +private struct FfiConverterTypeNimbusStringHelper: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = NimbusStringHelper - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> NimbusStringHelper { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -740,27 +673,21 @@ private extension NimbusStringHelper { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: NimbusStringHelper, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NimbusStringHelper { + return NimbusStringHelper(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: NimbusStringHelper) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension NimbusStringHelper: ViaFfi, Serializable {} - public struct AppContext { public var appName: String public var appId: String @@ -874,12 +801,12 @@ extension AppContext: Equatable, Hashable { } } -private extension AppContext { - static func read(from buf: Reader) throws -> AppContext { +private struct FfiConverterTypeAppContext: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AppContext { return try AppContext( - appName: String.read(from: buf), - appId: String.read(from: buf), - channel: String.read(from: buf), + appName: FfiConverterString.read(from: buf), + appId: FfiConverterString.read(from: buf), + channel: FfiConverterString.read(from: buf), appVersion: FfiConverterOptionString.read(from: buf), appBuild: FfiConverterOptionString.read(from: buf), architecture: FfiConverterOptionString.read(from: buf), @@ -892,32 +819,30 @@ private extension AppContext { debugTag: FfiConverterOptionString.read(from: buf), installationDate: FfiConverterOptionInt64.read(from: buf), homeDirectory: FfiConverterOptionString.read(from: buf), - customTargetingAttributes: FfiConverterOptionDictionaryString.read(from: buf) + customTargetingAttributes: FfiConverterOptionDictionaryStringString.read(from: buf) ) } - func write(into buf: Writer) { - appName.write(into: buf) - appId.write(into: buf) - channel.write(into: buf) - FfiConverterOptionString.write(appVersion, into: buf) - FfiConverterOptionString.write(appBuild, into: buf) - FfiConverterOptionString.write(architecture, into: buf) - FfiConverterOptionString.write(deviceManufacturer, into: buf) - FfiConverterOptionString.write(deviceModel, into: buf) - FfiConverterOptionString.write(locale, into: buf) - FfiConverterOptionString.write(os, into: buf) - FfiConverterOptionString.write(osVersion, into: buf) - FfiConverterOptionString.write(androidSdkVersion, into: buf) - FfiConverterOptionString.write(debugTag, into: buf) - FfiConverterOptionInt64.write(installationDate, into: buf) - FfiConverterOptionString.write(homeDirectory, into: buf) - FfiConverterOptionDictionaryString.write(customTargetingAttributes, into: buf) + fileprivate static func write(_ value: AppContext, into buf: Writer) { + FfiConverterString.write(value.appName, into: buf) + FfiConverterString.write(value.appId, into: buf) + FfiConverterString.write(value.channel, into: buf) + FfiConverterOptionString.write(value.appVersion, into: buf) + FfiConverterOptionString.write(value.appBuild, into: buf) + FfiConverterOptionString.write(value.architecture, into: buf) + FfiConverterOptionString.write(value.deviceManufacturer, into: buf) + FfiConverterOptionString.write(value.deviceModel, into: buf) + FfiConverterOptionString.write(value.locale, into: buf) + FfiConverterOptionString.write(value.os, into: buf) + FfiConverterOptionString.write(value.osVersion, into: buf) + FfiConverterOptionString.write(value.androidSdkVersion, into: buf) + FfiConverterOptionString.write(value.debugTag, into: buf) + FfiConverterOptionInt64.write(value.installationDate, into: buf) + FfiConverterOptionString.write(value.homeDirectory, into: buf) + FfiConverterOptionDictionaryStringString.write(value.customTargetingAttributes, into: buf) } } -extension AppContext: ViaFfiUsingByteBuffer, ViaFfi {} - public struct EnrolledExperiment { public var featureIds: [String] public var slug: String @@ -971,30 +896,28 @@ extension EnrolledExperiment: Equatable, Hashable { } } -private extension EnrolledExperiment { - static func read(from buf: Reader) throws -> EnrolledExperiment { +private struct FfiConverterTypeEnrolledExperiment: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> EnrolledExperiment { return try EnrolledExperiment( featureIds: FfiConverterSequenceString.read(from: buf), - slug: String.read(from: buf), - userFacingName: String.read(from: buf), - userFacingDescription: String.read(from: buf), - branchSlug: String.read(from: buf), - enrollmentId: String.read(from: buf) + slug: FfiConverterString.read(from: buf), + userFacingName: FfiConverterString.read(from: buf), + userFacingDescription: FfiConverterString.read(from: buf), + branchSlug: FfiConverterString.read(from: buf), + enrollmentId: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterSequenceString.write(featureIds, into: buf) - slug.write(into: buf) - userFacingName.write(into: buf) - userFacingDescription.write(into: buf) - branchSlug.write(into: buf) - enrollmentId.write(into: buf) + fileprivate static func write(_ value: EnrolledExperiment, into buf: Writer) { + FfiConverterSequenceString.write(value.featureIds, into: buf) + FfiConverterString.write(value.slug, into: buf) + FfiConverterString.write(value.userFacingName, into: buf) + FfiConverterString.write(value.userFacingDescription, into: buf) + FfiConverterString.write(value.branchSlug, into: buf) + FfiConverterString.write(value.enrollmentId, into: buf) } } -extension EnrolledExperiment: ViaFfiUsingByteBuffer, ViaFfi {} - public struct AvailableExperiment { public var slug: String public var userFacingName: String @@ -1042,28 +965,26 @@ extension AvailableExperiment: Equatable, Hashable { } } -private extension AvailableExperiment { - static func read(from buf: Reader) throws -> AvailableExperiment { +private struct FfiConverterTypeAvailableExperiment: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AvailableExperiment { return try AvailableExperiment( - slug: String.read(from: buf), - userFacingName: String.read(from: buf), - userFacingDescription: String.read(from: buf), - branches: FfiConverterSequenceRecordExperimentBranch.read(from: buf), + slug: FfiConverterString.read(from: buf), + userFacingName: FfiConverterString.read(from: buf), + userFacingDescription: FfiConverterString.read(from: buf), + branches: FfiConverterSequenceTypeExperimentBranch.read(from: buf), referenceBranch: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - slug.write(into: buf) - userFacingName.write(into: buf) - userFacingDescription.write(into: buf) - FfiConverterSequenceRecordExperimentBranch.write(branches, into: buf) - FfiConverterOptionString.write(referenceBranch, into: buf) + fileprivate static func write(_ value: AvailableExperiment, into buf: Writer) { + FfiConverterString.write(value.slug, into: buf) + FfiConverterString.write(value.userFacingName, into: buf) + FfiConverterString.write(value.userFacingDescription, into: buf) + FfiConverterSequenceTypeExperimentBranch.write(value.branches, into: buf) + FfiConverterOptionString.write(value.referenceBranch, into: buf) } } -extension AvailableExperiment: ViaFfiUsingByteBuffer, ViaFfi {} - public struct ExperimentBranch { public var slug: String public var ratio: Int32 @@ -1093,22 +1014,20 @@ extension ExperimentBranch: Equatable, Hashable { } } -private extension ExperimentBranch { - static func read(from buf: Reader) throws -> ExperimentBranch { +private struct FfiConverterTypeExperimentBranch: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> ExperimentBranch { return try ExperimentBranch( - slug: String.read(from: buf), - ratio: Int32.read(from: buf) + slug: FfiConverterString.read(from: buf), + ratio: FfiConverterInt32.read(from: buf) ) } - func write(into buf: Writer) { - slug.write(into: buf) - ratio.write(into: buf) + fileprivate static func write(_ value: ExperimentBranch, into buf: Writer) { + FfiConverterString.write(value.slug, into: buf) + FfiConverterInt32.write(value.ratio, into: buf) } } -extension ExperimentBranch: ViaFfiUsingByteBuffer, ViaFfi {} - public struct RemoteSettingsConfig { public var serverUrl: String public var collectionName: String @@ -1138,22 +1057,20 @@ extension RemoteSettingsConfig: Equatable, Hashable { } } -private extension RemoteSettingsConfig { - static func read(from buf: Reader) throws -> RemoteSettingsConfig { +private struct FfiConverterTypeRemoteSettingsConfig: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> RemoteSettingsConfig { return try RemoteSettingsConfig( - serverUrl: String.read(from: buf), - collectionName: String.read(from: buf) + serverUrl: FfiConverterString.read(from: buf), + collectionName: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - serverUrl.write(into: buf) - collectionName.write(into: buf) + fileprivate static func write(_ value: RemoteSettingsConfig, into buf: Writer) { + FfiConverterString.write(value.serverUrl, into: buf) + FfiConverterString.write(value.collectionName, into: buf) } } -extension RemoteSettingsConfig: ViaFfiUsingByteBuffer, ViaFfi {} - public struct AvailableRandomizationUnits { public var clientId: String? public var dummy: Int8 @@ -1183,22 +1100,20 @@ extension AvailableRandomizationUnits: Equatable, Hashable { } } -private extension AvailableRandomizationUnits { - static func read(from buf: Reader) throws -> AvailableRandomizationUnits { +private struct FfiConverterTypeAvailableRandomizationUnits: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AvailableRandomizationUnits { return try AvailableRandomizationUnits( clientId: FfiConverterOptionString.read(from: buf), - dummy: Int8.read(from: buf) + dummy: FfiConverterInt8.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterOptionString.write(clientId, into: buf) - dummy.write(into: buf) + fileprivate static func write(_ value: AvailableRandomizationUnits, into buf: Writer) { + FfiConverterOptionString.write(value.clientId, into: buf) + FfiConverterInt8.write(value.dummy, into: buf) } } -extension AvailableRandomizationUnits: ViaFfiUsingByteBuffer, ViaFfi {} - public struct EnrollmentChangeEvent { public var experimentSlug: String public var branchSlug: String @@ -1246,28 +1161,26 @@ extension EnrollmentChangeEvent: Equatable, Hashable { } } -private extension EnrollmentChangeEvent { - static func read(from buf: Reader) throws -> EnrollmentChangeEvent { +private struct FfiConverterTypeEnrollmentChangeEvent: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> EnrollmentChangeEvent { return try EnrollmentChangeEvent( - experimentSlug: String.read(from: buf), - branchSlug: String.read(from: buf), - enrollmentId: String.read(from: buf), + experimentSlug: FfiConverterString.read(from: buf), + branchSlug: FfiConverterString.read(from: buf), + enrollmentId: FfiConverterString.read(from: buf), reason: FfiConverterOptionString.read(from: buf), - change: EnrollmentChangeEventType.read(from: buf) + change: FfiConverterTypeEnrollmentChangeEventType.read(from: buf) ) } - func write(into buf: Writer) { - experimentSlug.write(into: buf) - branchSlug.write(into: buf) - enrollmentId.write(into: buf) - FfiConverterOptionString.write(reason, into: buf) - change.write(into: buf) + fileprivate static func write(_ value: EnrollmentChangeEvent, into buf: Writer) { + FfiConverterString.write(value.experimentSlug, into: buf) + FfiConverterString.write(value.branchSlug, into: buf) + FfiConverterString.write(value.enrollmentId, into: buf) + FfiConverterOptionString.write(value.reason, into: buf) + FfiConverterTypeEnrollmentChangeEventType.write(value.change, into: buf) } } -extension EnrollmentChangeEvent: ViaFfiUsingByteBuffer, ViaFfi {} - public enum NimbusError { // Simple error enums only carry a message case InvalidPersistedData(message: String) @@ -1336,170 +1249,172 @@ public enum NimbusError { case VersionParsingError(message: String) } -extension NimbusError: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> NimbusError { +private struct FfiConverterTypeNimbusError: FfiConverterRustBuffer { + typealias SwiftType = NimbusError + + static func read(from buf: Reader) throws -> NimbusError { let variant: Int32 = try buf.readInt() switch variant { case 1: return .InvalidPersistedData( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 2: return .RkvError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 3: return .IoError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 4: return .JsonError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 5: return .EvaluationError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 6: return .InvalidExpression( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 7: return .InvalidFraction( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 8: return .TryFromSliceError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 9: return .EmptyRatiosError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 10: return .OutOfBoundsError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 11: return .UrlParsingError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 12: return .RequestError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 13: return .ResponseError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 14: return .UuidError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 15: return .InvalidExperimentFormat( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 16: return .InvalidPath( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 17: return .InternalError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 18: return .NoSuchExperiment( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 19: return .NoSuchBranch( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 20: return .BackoffError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 21: return .DatabaseNotReady( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 22: return .VersionParsingError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: NimbusError, into buf: Writer) { + switch value { case let .InvalidPersistedData(message): buf.writeInt(Int32(1)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .RkvError(message): buf.writeInt(Int32(2)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .IoError(message): buf.writeInt(Int32(3)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .JsonError(message): buf.writeInt(Int32(4)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .EvaluationError(message): buf.writeInt(Int32(5)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidExpression(message): buf.writeInt(Int32(6)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidFraction(message): buf.writeInt(Int32(7)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .TryFromSliceError(message): buf.writeInt(Int32(8)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .EmptyRatiosError(message): buf.writeInt(Int32(9)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .OutOfBoundsError(message): buf.writeInt(Int32(10)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UrlParsingError(message): buf.writeInt(Int32(11)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .RequestError(message): buf.writeInt(Int32(12)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .ResponseError(message): buf.writeInt(Int32(13)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UuidError(message): buf.writeInt(Int32(14)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidExperimentFormat(message): buf.writeInt(Int32(15)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidPath(message): buf.writeInt(Int32(16)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InternalError(message): buf.writeInt(Int32(17)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .NoSuchExperiment(message): buf.writeInt(Int32(18)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .NoSuchBranch(message): buf.writeInt(Int32(19)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .BackoffError(message): buf.writeInt(Int32(20)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .DatabaseNotReady(message): buf.writeInt(Int32(21)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .VersionParsingError(message): buf.writeInt(Int32(22)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) } } } @@ -1507,90 +1422,90 @@ extension NimbusError: ViaFfiUsingByteBuffer, ViaFfi { extension NimbusError: Equatable, Hashable {} extension NimbusError: Error {} -private enum FfiConverterTypeJsonObject { - fileprivate static func read(_ buf: Reader) throws -> String { - return try String.read(from: buf) - } - - fileprivate static func write(_ value: String, _ buf: Writer) { - return value.write(into: buf) - } - fileprivate static func lift(_ value: RustBuffer) throws -> String { - return try String.lift(value) - } - - fileprivate static func lower(_ value: String) -> RustBuffer { - return value.lower() - } -} +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias JsonObject = String +private typealias FfiConverterTypeJsonObject = FfiConverterString +private struct FfiConverterInt8: FfiConverterPrimitive { + typealias FfiType = Int8 + typealias SwiftType = Int8 -extension Int8: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> Int8 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int8, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Int32: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterInt32: FfiConverterPrimitive { + typealias FfiType = Int32 + typealias SwiftType = Int32 + + static func read(from buf: Reader) throws -> Int32 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int32, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Int64: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterInt64: FfiConverterPrimitive { + typealias FfiType = Int64 + typealias SwiftType = Int64 + + static func read(from buf: Reader) throws -> Int64 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int64, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Bool: ViaFfi { - fileprivate typealias FfiType = Int8 +private struct FfiConverterBool: FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool - fileprivate static func read(from buf: Reader) throws -> Self { - return try lift(buf.readInt()) + static func lift(_ value: Int8) throws -> Bool { + return value != 0 } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 } - fileprivate static func lift(_ v: FfiType) throws -> Self { - return v != 0 + static func read(from buf: Reader) throws -> Bool { + return try lift(buf.readInt()) } - fileprivate func lower() -> FfiType { - return self ? 1 : 0 + static func write(_ value: Bool, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension String: ViaFfi { - fileprivate typealias FfiType = RustBuffer +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer - fileprivate static func lift(_ v: FfiType) throws -> Self { + static func lift(_ value: RustBuffer) throws -> String { defer { - v.deallocate() + value.deallocate() } - if v.data == nil { + if value.data == nil { return String() } - let bytes = UnsafeBufferPointer(start: v.data!, count: Int(v.len)) + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) return String(bytes: bytes, encoding: String.Encoding.utf8)! } - fileprivate func lower() -> FfiType { - return utf8CString.withUnsafeBufferPointer { ptr in + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in // The swift string gives us int8_t, we want uint8_t. ptr.withMemoryRebound(to: UInt8.self) { ptr in // The swift string gives us a trailing null byte, we don't want it. @@ -1600,15 +1515,15 @@ extension String: ViaFfi { } } - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> String { let len: Int32 = try buf.readInt() return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! } - fileprivate func write(into buf: Writer) { - let len = Int32(utf8.count) + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) buf.writeInt(len) - buf.writeBytes(utf8) + buf.writeBytes(value.utf8) } } @@ -1625,181 +1540,241 @@ extension String: ViaFfi { // Helper code for EnrollmentChangeEventType enum is found in EnumTemplate.swift // Helper code for NimbusError error is found in ErrorTemplate.swift -private enum FfiConverterOptionInt64: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionInt64: FfiConverterRustBuffer { typealias SwiftType = Int64? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterInt64.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try Int64.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterInt64.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try String.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordRemoteSettingsConfig: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeRemoteSettingsConfig: FfiConverterRustBuffer { typealias SwiftType = RemoteSettingsConfig? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeRemoteSettingsConfig.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try RemoteSettingsConfig.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeRemoteSettingsConfig.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionDictionaryString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionDictionaryStringString: FfiConverterRustBuffer { typealias SwiftType = [String: String]? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterDictionaryString.write(item, into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterDictionaryStringString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterDictionaryString.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterDictionaryStringString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionJsonObject: FfiConverterUsingByteBuffer { - typealias SwiftType = String? +private struct FfiConverterOptionTypeJsonObject: FfiConverterRustBuffer { + typealias SwiftType = JsonObject? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterTypeJsonObject.write(item, buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeJsonObject.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterTypeJsonObject.read(buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeJsonObject.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterSequenceString: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterString.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try String.read(from: buf) + static func read(from buf: Reader) throws -> [String] { + let len: Int32 = try buf.readInt() + var seq = [String]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterString.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordAvailableExperiment: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeAvailableExperiment: FfiConverterRustBuffer { typealias SwiftType = [AvailableExperiment] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [AvailableExperiment], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeAvailableExperiment.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try AvailableExperiment.read(from: buf) + static func read(from buf: Reader) throws -> [AvailableExperiment] { + let len: Int32 = try buf.readInt() + var seq = [AvailableExperiment]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeAvailableExperiment.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordEnrolledExperiment: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeEnrolledExperiment: FfiConverterRustBuffer { typealias SwiftType = [EnrolledExperiment] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [EnrolledExperiment], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeEnrolledExperiment.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try EnrolledExperiment.read(from: buf) + static func read(from buf: Reader) throws -> [EnrolledExperiment] { + let len: Int32 = try buf.readInt() + var seq = [EnrolledExperiment]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeEnrolledExperiment.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordEnrollmentChangeEvent: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeEnrollmentChangeEvent: FfiConverterRustBuffer { typealias SwiftType = [EnrollmentChangeEvent] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [EnrollmentChangeEvent], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeEnrollmentChangeEvent.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try EnrollmentChangeEvent.read(from: buf) + static func read(from buf: Reader) throws -> [EnrollmentChangeEvent] { + let len: Int32 = try buf.readInt() + var seq = [EnrollmentChangeEvent]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeEnrollmentChangeEvent.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordExperimentBranch: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeExperimentBranch: FfiConverterRustBuffer { typealias SwiftType = [ExperimentBranch] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [ExperimentBranch], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeExperimentBranch.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try ExperimentBranch.read(from: buf) + static func read(from buf: Reader) throws -> [ExperimentBranch] { + let len: Int32 = try buf.readInt() + var seq = [ExperimentBranch]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeExperimentBranch.read(from: buf)) } + return seq } } -private enum FfiConverterDictionaryString: FfiConverterUsingByteBuffer { - typealias SwiftType = [String: String] - - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterDictionary.write(value, into: buf) { key, value, buf in - key.write(into: buf) - value.write(into: buf) +private struct FfiConverterDictionaryStringString: FfiConverterRustBuffer { + fileprivate static func write(_ value: [String: String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for (key, value) in value { + FfiConverterString.write(key, into: buf) + FfiConverterString.write(value, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterDictionary.read(from: buf) { buf in - (try String.read(from: buf), - try String.read(from: buf)) + fileprivate static func read(from buf: Reader) throws -> [String: String] { + let len: Int32 = try buf.readInt() + var dict = [String: String]() + dict.reserveCapacity(Int(len)) + for _ in 0 ..< len { + let key = try FfiConverterString.read(from: buf) + let value = try FfiConverterString.read(from: buf) + dict[key] = value } + return dict } } diff --git a/swift-source/all/Generated/nimbusFFI.h b/swift-source/all/Generated/nimbusFFI.h index 7463cdd3..bdd9ca26 100644 --- a/swift-source/all/Generated/nimbusFFI.h +++ b/swift-source/all/Generated/nimbusFFI.h @@ -46,115 +46,115 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_nimbus_302d_NimbusClient_object_free( +void ffi_nimbus_e97_NimbusClient_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull nimbus_302d_NimbusClient_new( +void*_Nonnull nimbus_e97_NimbusClient_new( RustBuffer app_ctx,RustBuffer dbpath,RustBuffer remote_settings_config,RustBuffer available_randomization_units, RustCallStatus *_Nonnull out_status ); -void nimbus_302d_NimbusClient_initialize( +void nimbus_e97_NimbusClient_initialize( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_experiment_branch( +RustBuffer nimbus_e97_NimbusClient_get_experiment_branch( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_feature_config_variables( +RustBuffer nimbus_e97_NimbusClient_get_feature_config_variables( void*_Nonnull ptr,RustBuffer feature_id, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_experiment_branches( +RustBuffer nimbus_e97_NimbusClient_get_experiment_branches( void*_Nonnull ptr,RustBuffer experiment_slug, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_active_experiments( +RustBuffer nimbus_e97_NimbusClient_get_active_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_available_experiments( +RustBuffer nimbus_e97_NimbusClient_get_available_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -int8_t nimbus_302d_NimbusClient_get_global_user_participation( +int8_t nimbus_e97_NimbusClient_get_global_user_participation( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_set_global_user_participation( +RustBuffer nimbus_e97_NimbusClient_set_global_user_participation( void*_Nonnull ptr,int8_t opt_in, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_update_experiments( +RustBuffer nimbus_e97_NimbusClient_update_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void nimbus_302d_NimbusClient_fetch_experiments( +void nimbus_e97_NimbusClient_fetch_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_apply_pending_experiments( +RustBuffer nimbus_e97_NimbusClient_apply_pending_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void nimbus_302d_NimbusClient_set_experiments_locally( +void nimbus_e97_NimbusClient_set_experiments_locally( void*_Nonnull ptr,RustBuffer experiments_json, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_opt_in_with_branch( +RustBuffer nimbus_e97_NimbusClient_opt_in_with_branch( void*_Nonnull ptr,RustBuffer experiment_slug,RustBuffer branch, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_opt_out( +RustBuffer nimbus_e97_NimbusClient_opt_out( void*_Nonnull ptr,RustBuffer experiment_slug, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_reset_telemetry_identifiers( +RustBuffer nimbus_e97_NimbusClient_reset_telemetry_identifiers( void*_Nonnull ptr,RustBuffer new_randomization_units, RustCallStatus *_Nonnull out_status ); -void*_Nonnull nimbus_302d_NimbusClient_create_targeting_helper( +void*_Nonnull nimbus_e97_NimbusClient_create_targeting_helper( void*_Nonnull ptr,RustBuffer additional_context, RustCallStatus *_Nonnull out_status ); -void*_Nonnull nimbus_302d_NimbusClient_create_string_helper( +void*_Nonnull nimbus_e97_NimbusClient_create_string_helper( void*_Nonnull ptr,RustBuffer additional_context, RustCallStatus *_Nonnull out_status ); -void ffi_nimbus_302d_NimbusTargetingHelper_object_free( +void ffi_nimbus_e97_NimbusTargetingHelper_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -int8_t nimbus_302d_NimbusTargetingHelper_eval_jexl( +int8_t nimbus_e97_NimbusTargetingHelper_eval_jexl( void*_Nonnull ptr,RustBuffer expression, RustCallStatus *_Nonnull out_status ); -void ffi_nimbus_302d_NimbusStringHelper_object_free( +void ffi_nimbus_e97_NimbusStringHelper_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusStringHelper_string_format( +RustBuffer nimbus_e97_NimbusStringHelper_string_format( void*_Nonnull ptr,RustBuffer template,RustBuffer uuid, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusStringHelper_get_uuid( +RustBuffer nimbus_e97_NimbusStringHelper_get_uuid( void*_Nonnull ptr,RustBuffer template, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_nimbus_302d_rustbuffer_alloc( +RustBuffer ffi_nimbus_e97_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_nimbus_302d_rustbuffer_from_bytes( +RustBuffer ffi_nimbus_e97_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_nimbus_302d_rustbuffer_free( +void ffi_nimbus_e97_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_nimbus_302d_rustbuffer_reserve( +RustBuffer ffi_nimbus_e97_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/swift-source/all/Generated/places.swift b/swift-source/all/Generated/places.swift index 6dcd5283..300ac618 100644 --- a/swift-source/all/Generated/places.swift +++ b/swift-source/all/Generated/places.swift @@ -19,13 +19,13 @@ private extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_places_4240_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_places_56cb_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_places_4240_rustbuffer_free(self, $0) } + try! rustCall { ffi_places_56cb_rustbuffer_free(self, $0) } } } @@ -147,45 +147,39 @@ private class Writer { } } -// Types conforming to `Serializable` can be read and written in a bytebuffer. -private protocol Serializable { - func write(into: Writer) - static func read(from: Reader) throws -> Self -} - -// Types confirming to `ViaFfi` can be transferred back-and-for over the FFI. -// This is analogous to the Rust trait of the same name. -private protocol ViaFfi: Serializable { +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { associatedtype FfiType - static func lift(_ v: FfiType) throws -> Self - func lower() -> FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol Primitive {} +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} -private extension Primitive { - typealias FfiType = Self - - static func lift(_ v: Self) throws -> Self { - return v +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value } - func lower() -> Self { - return self + static func lower(_ value: SwiftType) -> FfiType { + return value } } -// Types conforming to `ViaFfiUsingByteBuffer` lift and lower into a bytebuffer. -// Use this for complex types where it's hard to write a custom lift/lower. -private protocol ViaFfiUsingByteBuffer: Serializable {} - -private extension ViaFfiUsingByteBuffer { - typealias FfiType = RustBuffer +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - static func lift(_ buf: FfiType) throws -> Self { +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) + let value = try read(from: reader) if reader.hasRemaining() { throw UniffiInternalError.incompleteData } @@ -193,9 +187,9 @@ private extension ViaFfiUsingByteBuffer { return value } - func lower() -> FfiType { + static func lower(_ value: SwiftType) -> RustBuffer { let writer = Writer() - write(into: writer) + write(value, into: writer) return RustBuffer(bytes: writer.bytes) } } @@ -252,8 +246,11 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T }) } -private func rustCallWithError(_: E.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: { try E.lift($0) }) +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { @@ -271,7 +268,7 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) // with the message. But if that code panics, then it just sends back // an empty buffer. if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try String.lift(callStatus.errorBuf)) + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) } else { callStatus.errorBuf.deallocate() throw UniffiInternalError.rustPanic("Rust panic") @@ -282,103 +279,6 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -// Protocols for converters we'll implement in templates - -private protocol FfiConverter { - associatedtype SwiftType - associatedtype FfiType - - static func lift(_ ffiValue: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - - static func read(from: Reader) throws -> SwiftType - static func write(_ value: SwiftType, into: Writer) -} - -private protocol FfiConverterUsingByteBuffer: FfiConverter where FfiType == RustBuffer { - // Empty, because we want to declare some helper methods in the extension below. -} - -extension FfiConverterUsingByteBuffer { - static func lower(_ value: SwiftType) -> FfiType { - let writer = Writer() - Self.write(value, into: writer) - return RustBuffer(bytes: writer.bytes) - } - - static func lift(_ buf: FfiType) throws -> SwiftType { - let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) - if reader.hasRemaining() { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } -} - -// Helpers for structural types. Note that because of canonical_names, it /should/ be impossible -// to make another `FfiConverterSequence` etc just using the UDL. -private enum FfiConverterSequence { - static func write(_ value: [T], into buf: Writer, writeItem: (T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for item in value { - writeItem(item, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> [T] { - let len: Int32 = try buf.readInt() - var seq = [T]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try readItem(buf)) - } - return seq - } -} - -private enum FfiConverterOptional { - static func write(_ value: T?, into buf: Writer, writeItem: (T, Writer) -> Void) { - guard let value = value else { - buf.writeInt(Int8(0)) - return - } - buf.writeInt(Int8(1)) - writeItem(value, buf) - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> T? { - switch try buf.readInt() as Int8 { - case 0: return nil - case 1: return try readItem(buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -private enum FfiConverterDictionary { - static func write(_ value: [String: T], into buf: Writer, writeItem: (String, T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for (key, value) in value { - writeItem(key, value, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> (String, T)) throws -> [String: T] { - let len: Int32 = try buf.readInt() - var dict = [String: T]() - dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { - let (key, value) = try readItem(buf) - dict[key] = value - } - return dict - } -} - // Public interface members begin here. // Note that we don't yet support `indirect` for enums. @@ -390,19 +290,24 @@ public enum ConnectionType { case sync } -extension ConnectionType: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> ConnectionType { +private struct FfiConverterTypeConnectionType: FfiConverterRustBuffer { + typealias SwiftType = ConnectionType + + static func read(from buf: Reader) throws -> ConnectionType { let variant: Int32 = try buf.readInt() switch variant { case 1: return .readOnly + case 2: return .readWrite + case 3: return .sync + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: ConnectionType, into buf: Writer) { + switch value { case .readOnly: buf.writeInt(Int32(1)) @@ -425,18 +330,22 @@ public enum FrecencyThresholdOption { case skipOneTimePages } -extension FrecencyThresholdOption: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> FrecencyThresholdOption { +private struct FfiConverterTypeFrecencyThresholdOption: FfiConverterRustBuffer { + typealias SwiftType = FrecencyThresholdOption + + static func read(from buf: Reader) throws -> FrecencyThresholdOption { let variant: Int32 = try buf.readInt() switch variant { case 1: return .none + case 2: return .skipOneTimePages + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: FrecencyThresholdOption, into buf: Writer) { + switch value { case .none: buf.writeInt(Int32(1)) @@ -460,22 +369,30 @@ public enum MatchReason { case tags } -extension MatchReason: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> MatchReason { +private struct FfiConverterTypeMatchReason: FfiConverterRustBuffer { + typealias SwiftType = MatchReason + + static func read(from buf: Reader) throws -> MatchReason { let variant: Int32 = try buf.readInt() switch variant { case 1: return .keyword + case 2: return .origin + case 3: return .urlMatch + case 4: return .previousUse + case 5: return .bookmark + case 6: return .tags + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: MatchReason, into buf: Writer) { + switch value { case .keyword: buf.writeInt(Int32(1)) @@ -507,18 +424,22 @@ public enum DocumentType { case media } -extension DocumentType: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> DocumentType { +private struct FfiConverterTypeDocumentType: FfiConverterRustBuffer { + typealias SwiftType = DocumentType + + static func read(from buf: Reader) throws -> DocumentType { let variant: Int32 = try buf.readInt() switch variant { case 1: return .regular + case 2: return .media + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: DocumentType, into buf: Writer) { + switch value { case .regular: buf.writeInt(Int32(1)) @@ -545,25 +466,36 @@ public enum VisitTransition { case reload } -extension VisitTransition: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> VisitTransition { +private struct FfiConverterTypeVisitTransition: FfiConverterRustBuffer { + typealias SwiftType = VisitTransition + + static func read(from buf: Reader) throws -> VisitTransition { let variant: Int32 = try buf.readInt() switch variant { case 1: return .link + case 2: return .typed + case 3: return .bookmark + case 4: return .embed + case 5: return .redirectPermanent + case 6: return .redirectTemporary + case 7: return .download + case 8: return .framedLink + case 9: return .reload + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: VisitTransition, into buf: Writer) { + switch value { case .link: buf.writeInt(Int32(1)) @@ -605,36 +537,41 @@ public enum BookmarkItem { case folder(f: BookmarkFolder) } -extension BookmarkItem: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> BookmarkItem { +private struct FfiConverterTypeBookmarkItem: FfiConverterRustBuffer { + typealias SwiftType = BookmarkItem + + static func read(from buf: Reader) throws -> BookmarkItem { let variant: Int32 = try buf.readInt() switch variant { case 1: return .bookmark( - b: try BookmarkData.read(from: buf) + b: try FfiConverterTypeBookmarkData.read(from: buf) ) + case 2: return .separator( - s: try BookmarkSeparator.read(from: buf) + s: try FfiConverterTypeBookmarkSeparator.read(from: buf) ) + case 3: return .folder( - f: try BookmarkFolder.read(from: buf) + f: try FfiConverterTypeBookmarkFolder.read(from: buf) ) + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: BookmarkItem, into buf: Writer) { + switch value { case let .bookmark(b): buf.writeInt(Int32(1)) - b.write(into: buf) + FfiConverterTypeBookmarkData.write(b, into: buf) case let .separator(s): buf.writeInt(Int32(2)) - s.write(into: buf) + FfiConverterTypeBookmarkSeparator.write(s, into: buf) case let .folder(f): buf.writeInt(Int32(3)) - f.write(into: buf) + FfiConverterTypeBookmarkFolder.write(f, into: buf) } } } @@ -649,23 +586,27 @@ public enum BookmarkPosition { case append } -extension BookmarkPosition: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> BookmarkPosition { +private struct FfiConverterTypeBookmarkPosition: FfiConverterRustBuffer { + typealias SwiftType = BookmarkPosition + + static func read(from buf: Reader) throws -> BookmarkPosition { let variant: Int32 = try buf.readInt() switch variant { case 1: return .specific( - pos: try UInt32.read(from: buf) + pos: try FfiConverterUInt32.read(from: buf) ) + case 2: return .append + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: BookmarkPosition, into buf: Writer) { + switch value { case let .specific(pos): buf.writeInt(Int32(1)) - pos.write(into: buf) + FfiConverterUInt32.write(pos, into: buf) case .append: buf.writeInt(Int32(2)) @@ -684,36 +625,41 @@ public enum InsertableBookmarkItem { case separator(s: InsertableBookmarkSeparator) } -extension InsertableBookmarkItem: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> InsertableBookmarkItem { +private struct FfiConverterTypeInsertableBookmarkItem: FfiConverterRustBuffer { + typealias SwiftType = InsertableBookmarkItem + + static func read(from buf: Reader) throws -> InsertableBookmarkItem { let variant: Int32 = try buf.readInt() switch variant { case 1: return .bookmark( - b: try InsertableBookmark.read(from: buf) + b: try FfiConverterTypeInsertableBookmark.read(from: buf) ) + case 2: return .folder( - f: try InsertableBookmarkFolder.read(from: buf) + f: try FfiConverterTypeInsertableBookmarkFolder.read(from: buf) ) + case 3: return .separator( - s: try InsertableBookmarkSeparator.read(from: buf) + s: try FfiConverterTypeInsertableBookmarkSeparator.read(from: buf) ) + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: InsertableBookmarkItem, into buf: Writer) { + switch value { case let .bookmark(b): buf.writeInt(Int32(1)) - b.write(into: buf) + FfiConverterTypeInsertableBookmark.write(b, into: buf) case let .folder(f): buf.writeInt(Int32(2)) - f.write(into: buf) + FfiConverterTypeInsertableBookmarkFolder.write(f, into: buf) case let .separator(s): buf.writeInt(Int32(3)) - s.write(into: buf) + FfiConverterTypeInsertableBookmarkSeparator.write(s, into: buf) } } } @@ -721,12 +667,15 @@ extension InsertableBookmarkItem: ViaFfiUsingByteBuffer, ViaFfi { extension InsertableBookmarkItem: Equatable, Hashable {} public func placesApiNew(dbPath: String) throws -> PlacesApi { - let _retval = try + return try FfiConverterTypePlacesApi.lift( + try - rustCallWithError(PlacesError.self) { - places_4240_places_api_new(dbPath.lower(), $0) - } - return try PlacesApi.lift(_retval) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_places_api_new( + FfiConverterString.lower(dbPath), $0 + ) + } + ) } public protocol SqlInterruptHandleProtocol { @@ -737,28 +686,29 @@ public class SqlInterruptHandle: SqlInterruptHandleProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { - try! rustCall { ffi_places_4240_SqlInterruptHandle_object_free(pointer, $0) } + try! rustCall { ffi_places_56cb_SqlInterruptHandle_object_free(pointer, $0) } } public func interrupt() { try! rustCall { - places_4240_SqlInterruptHandle_interrupt(self.pointer, $0) + places_56cb_SqlInterruptHandle_interrupt(self.pointer, $0) } } } -private extension SqlInterruptHandle { +private struct FfiConverterTypeSqlInterruptHandle: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = SqlInterruptHandle - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> SqlInterruptHandle { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -769,33 +719,27 @@ private extension SqlInterruptHandle { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: SqlInterruptHandle, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SqlInterruptHandle { + return SqlInterruptHandle(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: SqlInterruptHandle) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension SqlInterruptHandle: ViaFfi, Serializable {} - public protocol PlacesApiProtocol { func newConnection(connType: ConnectionType) throws -> PlacesConnection func registerWithSyncManager() func resetHistory() throws - func historySync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String) throws -> String - func bookmarksSync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String) throws -> String + func historySync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: Url) throws -> String + func bookmarksSync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: Url) throws -> String func placesPinnedSitesImportFromFennec(dbPath: String) throws -> [BookmarkItem] func placesHistoryImportFromFennec(dbPath: String) throws -> String func placesBookmarksImportFromFennec(dbPath: String) throws -> String @@ -807,97 +751,117 @@ public class PlacesApi: PlacesApiProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { - try! rustCall { ffi_places_4240_PlacesApi_object_free(pointer, $0) } + try! rustCall { ffi_places_56cb_PlacesApi_object_free(pointer, $0) } } public func newConnection(connType: ConnectionType) throws -> PlacesConnection { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_new_connection(self.pointer, connType.lower(), $0) - } - return try PlacesConnection.lift(_retval) + return try FfiConverterTypePlacesConnection.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_new_connection(self.pointer, + FfiConverterTypeConnectionType.lower(connType), $0) + } + ) } public func registerWithSyncManager() { try! rustCall { - places_4240_PlacesApi_register_with_sync_manager(self.pointer, $0) + places_56cb_PlacesApi_register_with_sync_manager(self.pointer, $0) } } public func resetHistory() throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_reset_history(self.pointer, $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_reset_history(self.pointer, $0) } } - public func historySync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String) throws -> String { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_history_sync(self.pointer, keyId.lower(), accessToken.lower(), syncKey.lower(), FfiConverterTypeUrl.lower(tokenserverUrl), $0) - } - return try String.lift(_retval) + public func historySync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: Url) throws -> String { + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_history_sync(self.pointer, + FfiConverterString.lower(keyId), + FfiConverterString.lower(accessToken), + FfiConverterString.lower(syncKey), + FfiConverterTypeUrl.lower(tokenserverUrl), $0) + } + ) } - public func bookmarksSync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String) throws -> String { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_bookmarks_sync(self.pointer, keyId.lower(), accessToken.lower(), syncKey.lower(), FfiConverterTypeUrl.lower(tokenserverUrl), $0) - } - return try String.lift(_retval) + public func bookmarksSync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: Url) throws -> String { + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_bookmarks_sync(self.pointer, + FfiConverterString.lower(keyId), + FfiConverterString.lower(accessToken), + FfiConverterString.lower(syncKey), + FfiConverterTypeUrl.lower(tokenserverUrl), $0) + } + ) } public func placesPinnedSitesImportFromFennec(dbPath: String) throws -> [BookmarkItem] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_places_pinned_sites_import_from_fennec(self.pointer, dbPath.lower(), $0) - } - return try FfiConverterSequenceEnumBookmarkItem.lift(_retval) + return try FfiConverterSequenceTypeBookmarkItem.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_places_pinned_sites_import_from_fennec(self.pointer, + FfiConverterString.lower(dbPath), $0) + } + ) } public func placesHistoryImportFromFennec(dbPath: String) throws -> String { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_places_history_import_from_fennec(self.pointer, dbPath.lower(), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_places_history_import_from_fennec(self.pointer, + FfiConverterString.lower(dbPath), $0) + } + ) } public func placesBookmarksImportFromFennec(dbPath: String) throws -> String { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_places_bookmarks_import_from_fennec(self.pointer, dbPath.lower(), $0) - } - return try String.lift(_retval) + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_places_bookmarks_import_from_fennec(self.pointer, + FfiConverterString.lower(dbPath), $0) + } + ) } public func placesBookmarksImportFromIos(dbPath: String) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_places_bookmarks_import_from_ios(self.pointer, dbPath.lower(), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_places_bookmarks_import_from_ios(self.pointer, + FfiConverterString.lower(dbPath), $0) } } public func bookmarksReset() throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesApi_bookmarks_reset(self.pointer, $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesApi_bookmarks_reset(self.pointer, $0) } } } -private extension PlacesApi { +private struct FfiConverterTypePlacesApi: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = PlacesApi - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> PlacesApi { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -908,368 +872,438 @@ private extension PlacesApi { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: PlacesApi, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PlacesApi { + return PlacesApi(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: PlacesApi) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension PlacesApi: ViaFfi, Serializable {} - public protocol PlacesConnectionProtocol { func newInterruptHandle() -> SqlInterruptHandle - func getLatestHistoryMetadataForUrl(url: String) throws -> HistoryMetadata? - func getHistoryMetadataBetween(start: Int64, end: Int64) throws -> [HistoryMetadata] - func getHistoryMetadataSince(since: Int64) throws -> [HistoryMetadata] + func getLatestHistoryMetadataForUrl(url: Url) throws -> HistoryMetadata? + func getHistoryMetadataBetween(start: PlacesTimestamp, end: PlacesTimestamp) throws -> [HistoryMetadata] + func getHistoryMetadataSince(since: PlacesTimestamp) throws -> [HistoryMetadata] func queryAutocomplete(search: String, limit: Int32) throws -> [SearchResult] func acceptResult(searchString: String, url: String) throws - func matchUrl(query: String) throws -> String? + func matchUrl(query: String) throws -> Url? func queryHistoryMetadata(query: String, limit: Int32) throws -> [HistoryMetadata] func getHistoryHighlights(weights: HistoryHighlightWeights, limit: Int32) throws -> [HistoryHighlight] func noteHistoryMetadataObservation(data: HistoryMetadataObservation) throws - func metadataDelete(url: String, referrerUrl: String?, searchTerm: String?) throws - func metadataDeleteOlderThan(olderThan: Int64) throws + func metadataDelete(url: Url, referrerUrl: Url?, searchTerm: String?) throws + func metadataDeleteOlderThan(olderThan: PlacesTimestamp) throws func applyObservation(visit: VisitObservation) throws - func getVisitedUrlsInRange(start: Int64, end: Int64, includeRemote: Bool) throws -> [String] - func getVisitInfos(startDate: Int64, endDate: Int64, excludeTypes: Int32) throws -> [HistoryVisitInfo] - func getVisitCount(excludeTypes: Int32) throws -> Int64 - func getVisitPage(offset: Int64, count: Int64, excludeTypes: Int32) throws -> [HistoryVisitInfo] - func getVisitPageWithBound(bound: Int64, offset: Int64, count: Int64, excludeTypes: Int32) throws -> HistoryVisitInfosWithBound + func getVisitedUrlsInRange(start: PlacesTimestamp, end: PlacesTimestamp, includeRemote: Bool) throws -> [Url] + func getVisitInfos(startDate: PlacesTimestamp, endDate: PlacesTimestamp, excludeTypes: VisitTransitionSet) throws -> [HistoryVisitInfo] + func getVisitCount(excludeTypes: VisitTransitionSet) throws -> Int64 + func getVisitPage(offset: Int64, count: Int64, excludeTypes: VisitTransitionSet) throws -> [HistoryVisitInfo] + func getVisitPageWithBound(bound: Int64, offset: Int64, count: Int64, excludeTypes: VisitTransitionSet) throws -> HistoryVisitInfosWithBound func getVisited(urls: [String]) throws -> [Bool] func deleteVisitsFor(url: String) throws - func deleteVisitsBetween(start: Int64, end: Int64) throws - func deleteVisit(url: String, timestamp: Int64) throws + func deleteVisitsBetween(start: PlacesTimestamp, end: PlacesTimestamp) throws + func deleteVisit(url: String, timestamp: PlacesTimestamp) throws func getTopFrecentSiteInfos(numItems: Int32, thresholdOption: FrecencyThresholdOption) throws -> [TopFrecentSiteInfo] func wipeLocalHistory() throws func deleteEverythingHistory() throws func pruneDestructively() throws func runMaintenance() throws - func bookmarksGetTree(itemGuid: String) throws -> BookmarkItem? - func bookmarksGetByGuid(guid: String, getDirectChildren: Bool) throws -> BookmarkItem? + func bookmarksGetTree(itemGuid: Guid) throws -> BookmarkItem? + func bookmarksGetByGuid(guid: Guid, getDirectChildren: Bool) throws -> BookmarkItem? func bookmarksGetAllWithUrl(url: String) throws -> [BookmarkItem] func bookmarksSearch(query: String, limit: Int32) throws -> [BookmarkItem] func bookmarksGetRecent(limit: Int32) throws -> [BookmarkItem] - func bookmarksDelete(id: String) throws -> Bool + func bookmarksDelete(id: Guid) throws -> Bool func bookmarksDeleteEverything() throws - func bookmarksGetUrlForKeyword(keyword: String) throws -> String? + func bookmarksGetUrlForKeyword(keyword: String) throws -> Url? func bookmarksUpdate(data: BookmarkUpdateInfo) throws - func bookmarksInsert(bookmark: InsertableBookmarkItem) throws -> String + func bookmarksInsert(bookmark: InsertableBookmarkItem) throws -> Guid } public class PlacesConnection: PlacesConnectionProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { - try! rustCall { ffi_places_4240_PlacesConnection_object_free(pointer, $0) } + try! rustCall { ffi_places_56cb_PlacesConnection_object_free(pointer, $0) } } public func newInterruptHandle() -> SqlInterruptHandle { - let _retval = try! - rustCall { - places_4240_PlacesConnection_new_interrupt_handle(self.pointer, $0) - } - return try! SqlInterruptHandle.lift(_retval) + return try! FfiConverterTypeSqlInterruptHandle.lift( + try! + rustCall { + places_56cb_PlacesConnection_new_interrupt_handle(self.pointer, $0) + } + ) } - public func getLatestHistoryMetadataForUrl(url: String) throws -> HistoryMetadata? { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_latest_history_metadata_for_url(self.pointer, FfiConverterTypeUrl.lower(url), $0) - } - return try FfiConverterOptionRecordHistoryMetadata.lift(_retval) + public func getLatestHistoryMetadataForUrl(url: Url) throws -> HistoryMetadata? { + return try FfiConverterOptionTypeHistoryMetadata.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_latest_history_metadata_for_url(self.pointer, + FfiConverterTypeUrl.lower(url), $0) + } + ) } - public func getHistoryMetadataBetween(start: Int64, end: Int64) throws -> [HistoryMetadata] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_history_metadata_between(self.pointer, FfiConverterTypeTimestamp.lower(start), FfiConverterTypeTimestamp.lower(end), $0) - } - return try FfiConverterSequenceRecordHistoryMetadata.lift(_retval) + public func getHistoryMetadataBetween(start: PlacesTimestamp, end: PlacesTimestamp) throws -> [HistoryMetadata] { + return try FfiConverterSequenceTypeHistoryMetadata.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_history_metadata_between(self.pointer, + FfiConverterTypePlacesTimestamp.lower(start), + FfiConverterTypePlacesTimestamp.lower(end), $0) + } + ) } - public func getHistoryMetadataSince(since: Int64) throws -> [HistoryMetadata] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_history_metadata_since(self.pointer, FfiConverterTypeTimestamp.lower(since), $0) - } - return try FfiConverterSequenceRecordHistoryMetadata.lift(_retval) + public func getHistoryMetadataSince(since: PlacesTimestamp) throws -> [HistoryMetadata] { + return try FfiConverterSequenceTypeHistoryMetadata.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_history_metadata_since(self.pointer, + FfiConverterTypePlacesTimestamp.lower(since), $0) + } + ) } public func queryAutocomplete(search: String, limit: Int32) throws -> [SearchResult] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_query_autocomplete(self.pointer, search.lower(), limit.lower(), $0) - } - return try FfiConverterSequenceRecordSearchResult.lift(_retval) + return try FfiConverterSequenceTypeSearchResult.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_query_autocomplete(self.pointer, + FfiConverterString.lower(search), + FfiConverterInt32.lower(limit), $0) + } + ) } public func acceptResult(searchString: String, url: String) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_accept_result(self.pointer, searchString.lower(), url.lower(), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_accept_result(self.pointer, + FfiConverterString.lower(searchString), + FfiConverterString.lower(url), $0) } } - public func matchUrl(query: String) throws -> String? { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_match_url(self.pointer, query.lower(), $0) - } - return try FfiConverterOptionUrl.lift(_retval) + public func matchUrl(query: String) throws -> Url? { + return try FfiConverterOptionTypeUrl.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_match_url(self.pointer, + FfiConverterString.lower(query), $0) + } + ) } public func queryHistoryMetadata(query: String, limit: Int32) throws -> [HistoryMetadata] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_query_history_metadata(self.pointer, query.lower(), limit.lower(), $0) - } - return try FfiConverterSequenceRecordHistoryMetadata.lift(_retval) + return try FfiConverterSequenceTypeHistoryMetadata.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_query_history_metadata(self.pointer, + FfiConverterString.lower(query), + FfiConverterInt32.lower(limit), $0) + } + ) } public func getHistoryHighlights(weights: HistoryHighlightWeights, limit: Int32) throws -> [HistoryHighlight] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_history_highlights(self.pointer, weights.lower(), limit.lower(), $0) - } - return try FfiConverterSequenceRecordHistoryHighlight.lift(_retval) + return try FfiConverterSequenceTypeHistoryHighlight.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_history_highlights(self.pointer, + FfiConverterTypeHistoryHighlightWeights.lower(weights), + FfiConverterInt32.lower(limit), $0) + } + ) } public func noteHistoryMetadataObservation(data: HistoryMetadataObservation) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_note_history_metadata_observation(self.pointer, data.lower(), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_note_history_metadata_observation(self.pointer, + FfiConverterTypeHistoryMetadataObservation.lower(data), $0) } } - public func metadataDelete(url: String, referrerUrl: String?, searchTerm: String?) throws { + public func metadataDelete(url: Url, referrerUrl: Url?, searchTerm: String?) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_metadata_delete(self.pointer, FfiConverterTypeUrl.lower(url), FfiConverterOptionUrl.lower(referrerUrl), FfiConverterOptionString.lower(searchTerm), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_metadata_delete(self.pointer, + FfiConverterTypeUrl.lower(url), + FfiConverterOptionTypeUrl.lower(referrerUrl), + FfiConverterOptionString.lower(searchTerm), $0) } } - public func metadataDeleteOlderThan(olderThan: Int64) throws { + public func metadataDeleteOlderThan(olderThan: PlacesTimestamp) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_metadata_delete_older_than(self.pointer, FfiConverterTypeTimestamp.lower(olderThan), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_metadata_delete_older_than(self.pointer, + FfiConverterTypePlacesTimestamp.lower(olderThan), $0) } } public func applyObservation(visit: VisitObservation) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_apply_observation(self.pointer, visit.lower(), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_apply_observation(self.pointer, + FfiConverterTypeVisitObservation.lower(visit), $0) } } - public func getVisitedUrlsInRange(start: Int64, end: Int64, includeRemote: Bool) throws -> [String] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_visited_urls_in_range(self.pointer, FfiConverterTypeTimestamp.lower(start), FfiConverterTypeTimestamp.lower(end), includeRemote.lower(), $0) - } - return try FfiConverterSequenceUrl.lift(_retval) + public func getVisitedUrlsInRange(start: PlacesTimestamp, end: PlacesTimestamp, includeRemote: Bool) throws -> [Url] { + return try FfiConverterSequenceTypeUrl.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_visited_urls_in_range(self.pointer, + FfiConverterTypePlacesTimestamp.lower(start), + FfiConverterTypePlacesTimestamp.lower(end), + FfiConverterBool.lower(includeRemote), $0) + } + ) } - public func getVisitInfos(startDate: Int64, endDate: Int64, excludeTypes: Int32) throws -> [HistoryVisitInfo] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_visit_infos(self.pointer, FfiConverterTypeTimestamp.lower(startDate), FfiConverterTypeTimestamp.lower(endDate), FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) - } - return try FfiConverterSequenceRecordHistoryVisitInfo.lift(_retval) + public func getVisitInfos(startDate: PlacesTimestamp, endDate: PlacesTimestamp, excludeTypes: VisitTransitionSet) throws -> [HistoryVisitInfo] { + return try FfiConverterSequenceTypeHistoryVisitInfo.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_visit_infos(self.pointer, + FfiConverterTypePlacesTimestamp.lower(startDate), + FfiConverterTypePlacesTimestamp.lower(endDate), + FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) + } + ) } - public func getVisitCount(excludeTypes: Int32) throws -> Int64 { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_visit_count(self.pointer, FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) - } - return try Int64.lift(_retval) + public func getVisitCount(excludeTypes: VisitTransitionSet) throws -> Int64 { + return try FfiConverterInt64.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_visit_count(self.pointer, + FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) + } + ) } - public func getVisitPage(offset: Int64, count: Int64, excludeTypes: Int32) throws -> [HistoryVisitInfo] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_visit_page(self.pointer, offset.lower(), count.lower(), FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) - } - return try FfiConverterSequenceRecordHistoryVisitInfo.lift(_retval) + public func getVisitPage(offset: Int64, count: Int64, excludeTypes: VisitTransitionSet) throws -> [HistoryVisitInfo] { + return try FfiConverterSequenceTypeHistoryVisitInfo.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_visit_page(self.pointer, + FfiConverterInt64.lower(offset), + FfiConverterInt64.lower(count), + FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) + } + ) } - public func getVisitPageWithBound(bound: Int64, offset: Int64, count: Int64, excludeTypes: Int32) throws -> HistoryVisitInfosWithBound { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_visit_page_with_bound(self.pointer, bound.lower(), offset.lower(), count.lower(), FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) - } - return try HistoryVisitInfosWithBound.lift(_retval) + public func getVisitPageWithBound(bound: Int64, offset: Int64, count: Int64, excludeTypes: VisitTransitionSet) throws -> HistoryVisitInfosWithBound { + return try FfiConverterTypeHistoryVisitInfosWithBound.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_visit_page_with_bound(self.pointer, + FfiConverterInt64.lower(bound), + FfiConverterInt64.lower(offset), + FfiConverterInt64.lower(count), + FfiConverterTypeVisitTransitionSet.lower(excludeTypes), $0) + } + ) } public func getVisited(urls: [String]) throws -> [Bool] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_visited(self.pointer, FfiConverterSequenceString.lower(urls), $0) - } - return try FfiConverterSequenceBool.lift(_retval) + return try FfiConverterSequenceBool.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_visited(self.pointer, + FfiConverterSequenceString.lower(urls), $0) + } + ) } public func deleteVisitsFor(url: String) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_delete_visits_for(self.pointer, url.lower(), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_delete_visits_for(self.pointer, + FfiConverterString.lower(url), $0) } } - public func deleteVisitsBetween(start: Int64, end: Int64) throws { + public func deleteVisitsBetween(start: PlacesTimestamp, end: PlacesTimestamp) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_delete_visits_between(self.pointer, FfiConverterTypeTimestamp.lower(start), FfiConverterTypeTimestamp.lower(end), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_delete_visits_between(self.pointer, + FfiConverterTypePlacesTimestamp.lower(start), + FfiConverterTypePlacesTimestamp.lower(end), $0) } } - public func deleteVisit(url: String, timestamp: Int64) throws { + public func deleteVisit(url: String, timestamp: PlacesTimestamp) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_delete_visit(self.pointer, url.lower(), FfiConverterTypeTimestamp.lower(timestamp), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_delete_visit(self.pointer, + FfiConverterString.lower(url), + FfiConverterTypePlacesTimestamp.lower(timestamp), $0) } } public func getTopFrecentSiteInfos(numItems: Int32, thresholdOption: FrecencyThresholdOption) throws -> [TopFrecentSiteInfo] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_get_top_frecent_site_infos(self.pointer, numItems.lower(), thresholdOption.lower(), $0) - } - return try FfiConverterSequenceRecordTopFrecentSiteInfo.lift(_retval) + return try FfiConverterSequenceTypeTopFrecentSiteInfo.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_get_top_frecent_site_infos(self.pointer, + FfiConverterInt32.lower(numItems), + FfiConverterTypeFrecencyThresholdOption.lower(thresholdOption), $0) + } + ) } public func wipeLocalHistory() throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_wipe_local_history(self.pointer, $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_wipe_local_history(self.pointer, $0) } } public func deleteEverythingHistory() throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_delete_everything_history(self.pointer, $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_delete_everything_history(self.pointer, $0) } } public func pruneDestructively() throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_prune_destructively(self.pointer, $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_prune_destructively(self.pointer, $0) } } public func runMaintenance() throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_run_maintenance(self.pointer, $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_run_maintenance(self.pointer, $0) } } - public func bookmarksGetTree(itemGuid: String) throws -> BookmarkItem? { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_get_tree(self.pointer, FfiConverterTypeGuid.lower(itemGuid), $0) - } - return try FfiConverterOptionEnumBookmarkItem.lift(_retval) + public func bookmarksGetTree(itemGuid: Guid) throws -> BookmarkItem? { + return try FfiConverterOptionTypeBookmarkItem.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_get_tree(self.pointer, + FfiConverterTypeGuid.lower(itemGuid), $0) + } + ) } - public func bookmarksGetByGuid(guid: String, getDirectChildren: Bool) throws -> BookmarkItem? { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_get_by_guid(self.pointer, FfiConverterTypeGuid.lower(guid), getDirectChildren.lower(), $0) - } - return try FfiConverterOptionEnumBookmarkItem.lift(_retval) + public func bookmarksGetByGuid(guid: Guid, getDirectChildren: Bool) throws -> BookmarkItem? { + return try FfiConverterOptionTypeBookmarkItem.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_get_by_guid(self.pointer, + FfiConverterTypeGuid.lower(guid), + FfiConverterBool.lower(getDirectChildren), $0) + } + ) } public func bookmarksGetAllWithUrl(url: String) throws -> [BookmarkItem] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_get_all_with_url(self.pointer, url.lower(), $0) - } - return try FfiConverterSequenceEnumBookmarkItem.lift(_retval) + return try FfiConverterSequenceTypeBookmarkItem.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_get_all_with_url(self.pointer, + FfiConverterString.lower(url), $0) + } + ) } public func bookmarksSearch(query: String, limit: Int32) throws -> [BookmarkItem] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_search(self.pointer, query.lower(), limit.lower(), $0) - } - return try FfiConverterSequenceEnumBookmarkItem.lift(_retval) + return try FfiConverterSequenceTypeBookmarkItem.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_search(self.pointer, + FfiConverterString.lower(query), + FfiConverterInt32.lower(limit), $0) + } + ) } public func bookmarksGetRecent(limit: Int32) throws -> [BookmarkItem] { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_get_recent(self.pointer, limit.lower(), $0) - } - return try FfiConverterSequenceEnumBookmarkItem.lift(_retval) + return try FfiConverterSequenceTypeBookmarkItem.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_get_recent(self.pointer, + FfiConverterInt32.lower(limit), $0) + } + ) } - public func bookmarksDelete(id: String) throws -> Bool { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_delete(self.pointer, FfiConverterTypeGuid.lower(id), $0) - } - return try Bool.lift(_retval) + public func bookmarksDelete(id: Guid) throws -> Bool { + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_delete(self.pointer, + FfiConverterTypeGuid.lower(id), $0) + } + ) } public func bookmarksDeleteEverything() throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_delete_everything(self.pointer, $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_delete_everything(self.pointer, $0) } } - public func bookmarksGetUrlForKeyword(keyword: String) throws -> String? { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_get_url_for_keyword(self.pointer, keyword.lower(), $0) - } - return try FfiConverterOptionUrl.lift(_retval) + public func bookmarksGetUrlForKeyword(keyword: String) throws -> Url? { + return try FfiConverterOptionTypeUrl.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_get_url_for_keyword(self.pointer, + FfiConverterString.lower(keyword), $0) + } + ) } public func bookmarksUpdate(data: BookmarkUpdateInfo) throws { try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_update(self.pointer, data.lower(), $0) + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_update(self.pointer, + FfiConverterTypeBookmarkUpdateInfo.lower(data), $0) } } - public func bookmarksInsert(bookmark: InsertableBookmarkItem) throws -> String { - let _retval = try - rustCallWithError(PlacesError.self) { - places_4240_PlacesConnection_bookmarks_insert(self.pointer, bookmark.lower(), $0) - } - return try FfiConverterTypeGuid.lift(_retval) + public func bookmarksInsert(bookmark: InsertableBookmarkItem) throws -> Guid { + return try FfiConverterTypeGuid.lift( + try + rustCallWithError(FfiConverterTypePlacesError.self) { + places_56cb_PlacesConnection_bookmarks_insert(self.pointer, + FfiConverterTypeInsertableBookmarkItem.lower(bookmark), $0) + } + ) } } -private extension PlacesConnection { +private struct FfiConverterTypePlacesConnection: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = PlacesConnection - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> PlacesConnection { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -1280,36 +1314,30 @@ private extension PlacesConnection { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: PlacesConnection, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PlacesConnection { + return PlacesConnection(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: PlacesConnection) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension PlacesConnection: ViaFfi, Serializable {} - public struct SearchResult { - public var url: String + public var url: Url public var title: String public var frecency: Int64 public var reasons: [MatchReason] // Default memberwise initializers are never public by default, so we // declare one manually. - public init(url: String, title: String, frecency: Int64, reasons: [MatchReason]) { + public init(url: Url, title: String, frecency: Int64, reasons: [MatchReason]) { self.url = url self.title = title self.frecency = frecency @@ -1342,26 +1370,24 @@ extension SearchResult: Equatable, Hashable { } } -private extension SearchResult { - static func read(from buf: Reader) throws -> SearchResult { +private struct FfiConverterTypeSearchResult: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> SearchResult { return try SearchResult( - url: FfiConverterTypeUrl.read(buf), - title: String.read(from: buf), - frecency: Int64.read(from: buf), - reasons: FfiConverterSequenceEnumMatchReason.read(from: buf) + url: FfiConverterTypeUrl.read(from: buf), + title: FfiConverterString.read(from: buf), + frecency: FfiConverterInt64.read(from: buf), + reasons: FfiConverterSequenceTypeMatchReason.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeUrl.write(url, buf) - title.write(into: buf) - frecency.write(into: buf) - FfiConverterSequenceEnumMatchReason.write(reasons, into: buf) + fileprivate static func write(_ value: SearchResult, into buf: Writer) { + FfiConverterTypeUrl.write(value.url, into: buf) + FfiConverterString.write(value.title, into: buf) + FfiConverterInt64.write(value.frecency, into: buf) + FfiConverterSequenceTypeMatchReason.write(value.reasons, into: buf) } } -extension SearchResult: ViaFfiUsingByteBuffer, ViaFfi {} - public struct HistoryMetadataObservation { public var url: String public var referrerUrl: String? @@ -1415,30 +1441,28 @@ extension HistoryMetadataObservation: Equatable, Hashable { } } -private extension HistoryMetadataObservation { - static func read(from buf: Reader) throws -> HistoryMetadataObservation { +private struct FfiConverterTypeHistoryMetadataObservation: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> HistoryMetadataObservation { return try HistoryMetadataObservation( - url: String.read(from: buf), + url: FfiConverterString.read(from: buf), referrerUrl: FfiConverterOptionString.read(from: buf), searchTerm: FfiConverterOptionString.read(from: buf), viewTime: FfiConverterOptionInt32.read(from: buf), - documentType: FfiConverterOptionEnumDocumentType.read(from: buf), + documentType: FfiConverterOptionTypeDocumentType.read(from: buf), title: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - url.write(into: buf) - FfiConverterOptionString.write(referrerUrl, into: buf) - FfiConverterOptionString.write(searchTerm, into: buf) - FfiConverterOptionInt32.write(viewTime, into: buf) - FfiConverterOptionEnumDocumentType.write(documentType, into: buf) - FfiConverterOptionString.write(title, into: buf) + fileprivate static func write(_ value: HistoryMetadataObservation, into buf: Writer) { + FfiConverterString.write(value.url, into: buf) + FfiConverterOptionString.write(value.referrerUrl, into: buf) + FfiConverterOptionString.write(value.searchTerm, into: buf) + FfiConverterOptionInt32.write(value.viewTime, into: buf) + FfiConverterOptionTypeDocumentType.write(value.documentType, into: buf) + FfiConverterOptionString.write(value.title, into: buf) } } -extension HistoryMetadataObservation: ViaFfiUsingByteBuffer, ViaFfi {} - public struct HistoryMetadata { public var url: String public var title: String? @@ -1510,36 +1534,34 @@ extension HistoryMetadata: Equatable, Hashable { } } -private extension HistoryMetadata { - static func read(from buf: Reader) throws -> HistoryMetadata { +private struct FfiConverterTypeHistoryMetadata: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> HistoryMetadata { return try HistoryMetadata( - url: String.read(from: buf), + url: FfiConverterString.read(from: buf), title: FfiConverterOptionString.read(from: buf), previewImageUrl: FfiConverterOptionString.read(from: buf), - createdAt: Int64.read(from: buf), - updatedAt: Int64.read(from: buf), - totalViewTime: Int32.read(from: buf), + createdAt: FfiConverterInt64.read(from: buf), + updatedAt: FfiConverterInt64.read(from: buf), + totalViewTime: FfiConverterInt32.read(from: buf), searchTerm: FfiConverterOptionString.read(from: buf), - documentType: DocumentType.read(from: buf), + documentType: FfiConverterTypeDocumentType.read(from: buf), referrerUrl: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - url.write(into: buf) - FfiConverterOptionString.write(title, into: buf) - FfiConverterOptionString.write(previewImageUrl, into: buf) - createdAt.write(into: buf) - updatedAt.write(into: buf) - totalViewTime.write(into: buf) - FfiConverterOptionString.write(searchTerm, into: buf) - documentType.write(into: buf) - FfiConverterOptionString.write(referrerUrl, into: buf) + fileprivate static func write(_ value: HistoryMetadata, into buf: Writer) { + FfiConverterString.write(value.url, into: buf) + FfiConverterOptionString.write(value.title, into: buf) + FfiConverterOptionString.write(value.previewImageUrl, into: buf) + FfiConverterInt64.write(value.createdAt, into: buf) + FfiConverterInt64.write(value.updatedAt, into: buf) + FfiConverterInt32.write(value.totalViewTime, into: buf) + FfiConverterOptionString.write(value.searchTerm, into: buf) + FfiConverterTypeDocumentType.write(value.documentType, into: buf) + FfiConverterOptionString.write(value.referrerUrl, into: buf) } } -extension HistoryMetadata: ViaFfiUsingByteBuffer, ViaFfi {} - public struct HistoryHighlightWeights { public var viewTime: Double public var frequency: Double @@ -1569,22 +1591,20 @@ extension HistoryHighlightWeights: Equatable, Hashable { } } -private extension HistoryHighlightWeights { - static func read(from buf: Reader) throws -> HistoryHighlightWeights { +private struct FfiConverterTypeHistoryHighlightWeights: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> HistoryHighlightWeights { return try HistoryHighlightWeights( - viewTime: Double.read(from: buf), - frequency: Double.read(from: buf) + viewTime: FfiConverterDouble.read(from: buf), + frequency: FfiConverterDouble.read(from: buf) ) } - func write(into buf: Writer) { - viewTime.write(into: buf) - frequency.write(into: buf) + fileprivate static func write(_ value: HistoryHighlightWeights, into buf: Writer) { + FfiConverterDouble.write(value.viewTime, into: buf) + FfiConverterDouble.write(value.frequency, into: buf) } } -extension HistoryHighlightWeights: ViaFfiUsingByteBuffer, ViaFfi {} - public struct HistoryHighlight { public var score: Double public var placeId: Int32 @@ -1632,40 +1652,38 @@ extension HistoryHighlight: Equatable, Hashable { } } -private extension HistoryHighlight { - static func read(from buf: Reader) throws -> HistoryHighlight { +private struct FfiConverterTypeHistoryHighlight: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> HistoryHighlight { return try HistoryHighlight( - score: Double.read(from: buf), - placeId: Int32.read(from: buf), - url: String.read(from: buf), + score: FfiConverterDouble.read(from: buf), + placeId: FfiConverterInt32.read(from: buf), + url: FfiConverterString.read(from: buf), title: FfiConverterOptionString.read(from: buf), previewImageUrl: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - score.write(into: buf) - placeId.write(into: buf) - url.write(into: buf) - FfiConverterOptionString.write(title, into: buf) - FfiConverterOptionString.write(previewImageUrl, into: buf) + fileprivate static func write(_ value: HistoryHighlight, into buf: Writer) { + FfiConverterDouble.write(value.score, into: buf) + FfiConverterInt32.write(value.placeId, into: buf) + FfiConverterString.write(value.url, into: buf) + FfiConverterOptionString.write(value.title, into: buf) + FfiConverterOptionString.write(value.previewImageUrl, into: buf) } } -extension HistoryHighlight: ViaFfiUsingByteBuffer, ViaFfi {} - public struct HistoryVisitInfo { - public var url: String + public var url: Url public var title: String? - public var timestamp: Int64 + public var timestamp: PlacesTimestamp public var visitType: VisitTransition public var isHidden: Bool - public var previewImageUrl: String? + public var previewImageUrl: Url? public var isRemote: Bool // Default memberwise initializers are never public by default, so we // declare one manually. - public init(url: String, title: String?, timestamp: Int64, visitType: VisitTransition, isHidden: Bool, previewImageUrl: String?, isRemote: Bool) { + public init(url: Url, title: String?, timestamp: PlacesTimestamp, visitType: VisitTransition, isHidden: Bool, previewImageUrl: Url?, isRemote: Bool) { self.url = url self.title = title self.timestamp = timestamp @@ -1713,32 +1731,30 @@ extension HistoryVisitInfo: Equatable, Hashable { } } -private extension HistoryVisitInfo { - static func read(from buf: Reader) throws -> HistoryVisitInfo { +private struct FfiConverterTypeHistoryVisitInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> HistoryVisitInfo { return try HistoryVisitInfo( - url: FfiConverterTypeUrl.read(buf), + url: FfiConverterTypeUrl.read(from: buf), title: FfiConverterOptionString.read(from: buf), - timestamp: FfiConverterTypeTimestamp.read(buf), - visitType: VisitTransition.read(from: buf), - isHidden: Bool.read(from: buf), - previewImageUrl: FfiConverterOptionUrl.read(from: buf), - isRemote: Bool.read(from: buf) + timestamp: FfiConverterTypePlacesTimestamp.read(from: buf), + visitType: FfiConverterTypeVisitTransition.read(from: buf), + isHidden: FfiConverterBool.read(from: buf), + previewImageUrl: FfiConverterOptionTypeUrl.read(from: buf), + isRemote: FfiConverterBool.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeUrl.write(url, buf) - FfiConverterOptionString.write(title, into: buf) - FfiConverterTypeTimestamp.write(timestamp, buf) - visitType.write(into: buf) - isHidden.write(into: buf) - FfiConverterOptionUrl.write(previewImageUrl, into: buf) - isRemote.write(into: buf) + fileprivate static func write(_ value: HistoryVisitInfo, into buf: Writer) { + FfiConverterTypeUrl.write(value.url, into: buf) + FfiConverterOptionString.write(value.title, into: buf) + FfiConverterTypePlacesTimestamp.write(value.timestamp, into: buf) + FfiConverterTypeVisitTransition.write(value.visitType, into: buf) + FfiConverterBool.write(value.isHidden, into: buf) + FfiConverterOptionTypeUrl.write(value.previewImageUrl, into: buf) + FfiConverterBool.write(value.isRemote, into: buf) } } -extension HistoryVisitInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct HistoryVisitInfosWithBound { public var infos: [HistoryVisitInfo] public var bound: Int64 @@ -1774,39 +1790,37 @@ extension HistoryVisitInfosWithBound: Equatable, Hashable { } } -private extension HistoryVisitInfosWithBound { - static func read(from buf: Reader) throws -> HistoryVisitInfosWithBound { +private struct FfiConverterTypeHistoryVisitInfosWithBound: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> HistoryVisitInfosWithBound { return try HistoryVisitInfosWithBound( - infos: FfiConverterSequenceRecordHistoryVisitInfo.read(from: buf), - bound: Int64.read(from: buf), - offset: Int64.read(from: buf) + infos: FfiConverterSequenceTypeHistoryVisitInfo.read(from: buf), + bound: FfiConverterInt64.read(from: buf), + offset: FfiConverterInt64.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterSequenceRecordHistoryVisitInfo.write(infos, into: buf) - bound.write(into: buf) - offset.write(into: buf) + fileprivate static func write(_ value: HistoryVisitInfosWithBound, into buf: Writer) { + FfiConverterSequenceTypeHistoryVisitInfo.write(value.infos, into: buf) + FfiConverterInt64.write(value.bound, into: buf) + FfiConverterInt64.write(value.offset, into: buf) } } -extension HistoryVisitInfosWithBound: ViaFfiUsingByteBuffer, ViaFfi {} - public struct VisitObservation { - public var url: String + public var url: Url public var title: String? public var visitType: VisitTransition? public var isError: Bool? public var isRedirectSource: Bool? public var isPermanentRedirectSource: Bool? - public var at: Int64? - public var referrer: String? + public var at: PlacesTimestamp? + public var referrer: Url? public var isRemote: Bool? - public var previewImageUrl: String? + public var previewImageUrl: Url? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(url: String, title: String? = nil, visitType: VisitTransition?, isError: Bool? = nil, isRedirectSource: Bool? = nil, isPermanentRedirectSource: Bool? = nil, at: Int64? = nil, referrer: String? = nil, isRemote: Bool? = nil, previewImageUrl: String? = nil) { + public init(url: Url, title: String? = nil, visitType: VisitTransition?, isError: Bool? = nil, isRedirectSource: Bool? = nil, isPermanentRedirectSource: Bool? = nil, at: PlacesTimestamp? = nil, referrer: Url? = nil, isRemote: Bool? = nil, previewImageUrl: Url? = nil) { self.url = url self.title = title self.visitType = visitType @@ -1869,38 +1883,36 @@ extension VisitObservation: Equatable, Hashable { } } -private extension VisitObservation { - static func read(from buf: Reader) throws -> VisitObservation { +private struct FfiConverterTypeVisitObservation: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> VisitObservation { return try VisitObservation( - url: FfiConverterTypeUrl.read(buf), + url: FfiConverterTypeUrl.read(from: buf), title: FfiConverterOptionString.read(from: buf), - visitType: FfiConverterOptionEnumVisitTransition.read(from: buf), + visitType: FfiConverterOptionTypeVisitTransition.read(from: buf), isError: FfiConverterOptionBool.read(from: buf), isRedirectSource: FfiConverterOptionBool.read(from: buf), isPermanentRedirectSource: FfiConverterOptionBool.read(from: buf), - at: FfiConverterOptionTimestamp.read(from: buf), - referrer: FfiConverterOptionUrl.read(from: buf), + at: FfiConverterOptionTypePlacesTimestamp.read(from: buf), + referrer: FfiConverterOptionTypeUrl.read(from: buf), isRemote: FfiConverterOptionBool.read(from: buf), - previewImageUrl: FfiConverterOptionUrl.read(from: buf) + previewImageUrl: FfiConverterOptionTypeUrl.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeUrl.write(url, buf) - FfiConverterOptionString.write(title, into: buf) - FfiConverterOptionEnumVisitTransition.write(visitType, into: buf) - FfiConverterOptionBool.write(isError, into: buf) - FfiConverterOptionBool.write(isRedirectSource, into: buf) - FfiConverterOptionBool.write(isPermanentRedirectSource, into: buf) - FfiConverterOptionTimestamp.write(at, into: buf) - FfiConverterOptionUrl.write(referrer, into: buf) - FfiConverterOptionBool.write(isRemote, into: buf) - FfiConverterOptionUrl.write(previewImageUrl, into: buf) + fileprivate static func write(_ value: VisitObservation, into buf: Writer) { + FfiConverterTypeUrl.write(value.url, into: buf) + FfiConverterOptionString.write(value.title, into: buf) + FfiConverterOptionTypeVisitTransition.write(value.visitType, into: buf) + FfiConverterOptionBool.write(value.isError, into: buf) + FfiConverterOptionBool.write(value.isRedirectSource, into: buf) + FfiConverterOptionBool.write(value.isPermanentRedirectSource, into: buf) + FfiConverterOptionTypePlacesTimestamp.write(value.at, into: buf) + FfiConverterOptionTypeUrl.write(value.referrer, into: buf) + FfiConverterOptionBool.write(value.isRemote, into: buf) + FfiConverterOptionTypeUrl.write(value.previewImageUrl, into: buf) } } -extension VisitObservation: ViaFfiUsingByteBuffer, ViaFfi {} - public struct Dummy { public var md: [HistoryMetadata]? @@ -1924,27 +1936,25 @@ extension Dummy: Equatable, Hashable { } } -private extension Dummy { - static func read(from buf: Reader) throws -> Dummy { +private struct FfiConverterTypeDummy: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> Dummy { return try Dummy( - md: FfiConverterOptionSequenceRecordHistoryMetadata.read(from: buf) + md: FfiConverterOptionSequenceTypeHistoryMetadata.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterOptionSequenceRecordHistoryMetadata.write(md, into: buf) + fileprivate static func write(_ value: Dummy, into buf: Writer) { + FfiConverterOptionSequenceTypeHistoryMetadata.write(value.md, into: buf) } } -extension Dummy: ViaFfiUsingByteBuffer, ViaFfi {} - public struct TopFrecentSiteInfo { - public var url: String + public var url: Url public var title: String? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(url: String, title: String?) { + public init(url: Url, title: String?) { self.url = url self.title = title } @@ -1967,34 +1977,32 @@ extension TopFrecentSiteInfo: Equatable, Hashable { } } -private extension TopFrecentSiteInfo { - static func read(from buf: Reader) throws -> TopFrecentSiteInfo { +private struct FfiConverterTypeTopFrecentSiteInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> TopFrecentSiteInfo { return try TopFrecentSiteInfo( - url: FfiConverterTypeUrl.read(buf), + url: FfiConverterTypeUrl.read(from: buf), title: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeUrl.write(url, buf) - FfiConverterOptionString.write(title, into: buf) + fileprivate static func write(_ value: TopFrecentSiteInfo, into buf: Writer) { + FfiConverterTypeUrl.write(value.url, into: buf) + FfiConverterOptionString.write(value.title, into: buf) } } -extension TopFrecentSiteInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct BookmarkData { - public var guid: String - public var parentGuid: String + public var guid: Guid + public var parentGuid: Guid public var position: UInt32 - public var dateAdded: Int64 - public var lastModified: Int64 - public var url: String + public var dateAdded: PlacesTimestamp + public var lastModified: PlacesTimestamp + public var url: Url public var title: String? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(guid: String, parentGuid: String, position: UInt32, dateAdded: Int64, lastModified: Int64, url: String, title: String?) { + public init(guid: Guid, parentGuid: Guid, position: UInt32, dateAdded: PlacesTimestamp, lastModified: PlacesTimestamp, url: Url, title: String?) { self.guid = guid self.parentGuid = parentGuid self.position = position @@ -2042,42 +2050,40 @@ extension BookmarkData: Equatable, Hashable { } } -private extension BookmarkData { - static func read(from buf: Reader) throws -> BookmarkData { +private struct FfiConverterTypeBookmarkData: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> BookmarkData { return try BookmarkData( - guid: FfiConverterTypeGuid.read(buf), - parentGuid: FfiConverterTypeGuid.read(buf), - position: UInt32.read(from: buf), - dateAdded: FfiConverterTypeTimestamp.read(buf), - lastModified: FfiConverterTypeTimestamp.read(buf), - url: FfiConverterTypeUrl.read(buf), + guid: FfiConverterTypeGuid.read(from: buf), + parentGuid: FfiConverterTypeGuid.read(from: buf), + position: FfiConverterUInt32.read(from: buf), + dateAdded: FfiConverterTypePlacesTimestamp.read(from: buf), + lastModified: FfiConverterTypePlacesTimestamp.read(from: buf), + url: FfiConverterTypeUrl.read(from: buf), title: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeGuid.write(guid, buf) - FfiConverterTypeGuid.write(parentGuid, buf) - position.write(into: buf) - FfiConverterTypeTimestamp.write(dateAdded, buf) - FfiConverterTypeTimestamp.write(lastModified, buf) - FfiConverterTypeUrl.write(url, buf) - FfiConverterOptionString.write(title, into: buf) + fileprivate static func write(_ value: BookmarkData, into buf: Writer) { + FfiConverterTypeGuid.write(value.guid, into: buf) + FfiConverterTypeGuid.write(value.parentGuid, into: buf) + FfiConverterUInt32.write(value.position, into: buf) + FfiConverterTypePlacesTimestamp.write(value.dateAdded, into: buf) + FfiConverterTypePlacesTimestamp.write(value.lastModified, into: buf) + FfiConverterTypeUrl.write(value.url, into: buf) + FfiConverterOptionString.write(value.title, into: buf) } } -extension BookmarkData: ViaFfiUsingByteBuffer, ViaFfi {} - public struct BookmarkSeparator { - public var guid: String - public var dateAdded: Int64 - public var lastModified: Int64 - public var parentGuid: String + public var guid: Guid + public var dateAdded: PlacesTimestamp + public var lastModified: PlacesTimestamp + public var parentGuid: Guid public var position: UInt32 // Default memberwise initializers are never public by default, so we // declare one manually. - public init(guid: String, dateAdded: Int64, lastModified: Int64, parentGuid: String, position: UInt32) { + public init(guid: Guid, dateAdded: PlacesTimestamp, lastModified: PlacesTimestamp, parentGuid: Guid, position: UInt32) { self.guid = guid self.dateAdded = dateAdded self.lastModified = lastModified @@ -2115,41 +2121,39 @@ extension BookmarkSeparator: Equatable, Hashable { } } -private extension BookmarkSeparator { - static func read(from buf: Reader) throws -> BookmarkSeparator { +private struct FfiConverterTypeBookmarkSeparator: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> BookmarkSeparator { return try BookmarkSeparator( - guid: FfiConverterTypeGuid.read(buf), - dateAdded: FfiConverterTypeTimestamp.read(buf), - lastModified: FfiConverterTypeTimestamp.read(buf), - parentGuid: FfiConverterTypeGuid.read(buf), - position: UInt32.read(from: buf) + guid: FfiConverterTypeGuid.read(from: buf), + dateAdded: FfiConverterTypePlacesTimestamp.read(from: buf), + lastModified: FfiConverterTypePlacesTimestamp.read(from: buf), + parentGuid: FfiConverterTypeGuid.read(from: buf), + position: FfiConverterUInt32.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeGuid.write(guid, buf) - FfiConverterTypeTimestamp.write(dateAdded, buf) - FfiConverterTypeTimestamp.write(lastModified, buf) - FfiConverterTypeGuid.write(parentGuid, buf) - position.write(into: buf) + fileprivate static func write(_ value: BookmarkSeparator, into buf: Writer) { + FfiConverterTypeGuid.write(value.guid, into: buf) + FfiConverterTypePlacesTimestamp.write(value.dateAdded, into: buf) + FfiConverterTypePlacesTimestamp.write(value.lastModified, into: buf) + FfiConverterTypeGuid.write(value.parentGuid, into: buf) + FfiConverterUInt32.write(value.position, into: buf) } } -extension BookmarkSeparator: ViaFfiUsingByteBuffer, ViaFfi {} - public struct BookmarkFolder { - public var guid: String - public var dateAdded: Int64 - public var lastModified: Int64 - public var parentGuid: String? + public var guid: Guid + public var dateAdded: PlacesTimestamp + public var lastModified: PlacesTimestamp + public var parentGuid: Guid? public var position: UInt32 public var title: String? - public var childGuids: [String]? + public var childGuids: [Guid]? public var childNodes: [BookmarkItem]? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(guid: String, dateAdded: Int64, lastModified: Int64, parentGuid: String?, position: UInt32, title: String?, childGuids: [String]?, childNodes: [BookmarkItem]?) { + public init(guid: Guid, dateAdded: PlacesTimestamp, lastModified: PlacesTimestamp, parentGuid: Guid?, position: UInt32, title: String?, childGuids: [Guid]?, childNodes: [BookmarkItem]?) { self.guid = guid self.dateAdded = dateAdded self.lastModified = lastModified @@ -2202,44 +2206,42 @@ extension BookmarkFolder: Equatable, Hashable { } } -private extension BookmarkFolder { - static func read(from buf: Reader) throws -> BookmarkFolder { +private struct FfiConverterTypeBookmarkFolder: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> BookmarkFolder { return try BookmarkFolder( - guid: FfiConverterTypeGuid.read(buf), - dateAdded: FfiConverterTypeTimestamp.read(buf), - lastModified: FfiConverterTypeTimestamp.read(buf), - parentGuid: FfiConverterOptionGuid.read(from: buf), - position: UInt32.read(from: buf), + guid: FfiConverterTypeGuid.read(from: buf), + dateAdded: FfiConverterTypePlacesTimestamp.read(from: buf), + lastModified: FfiConverterTypePlacesTimestamp.read(from: buf), + parentGuid: FfiConverterOptionTypeGuid.read(from: buf), + position: FfiConverterUInt32.read(from: buf), title: FfiConverterOptionString.read(from: buf), - childGuids: FfiConverterOptionSequenceGuid.read(from: buf), - childNodes: FfiConverterOptionSequenceEnumBookmarkItem.read(from: buf) + childGuids: FfiConverterOptionSequenceTypeGuid.read(from: buf), + childNodes: FfiConverterOptionSequenceTypeBookmarkItem.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeGuid.write(guid, buf) - FfiConverterTypeTimestamp.write(dateAdded, buf) - FfiConverterTypeTimestamp.write(lastModified, buf) - FfiConverterOptionGuid.write(parentGuid, into: buf) - position.write(into: buf) - FfiConverterOptionString.write(title, into: buf) - FfiConverterOptionSequenceGuid.write(childGuids, into: buf) - FfiConverterOptionSequenceEnumBookmarkItem.write(childNodes, into: buf) + fileprivate static func write(_ value: BookmarkFolder, into buf: Writer) { + FfiConverterTypeGuid.write(value.guid, into: buf) + FfiConverterTypePlacesTimestamp.write(value.dateAdded, into: buf) + FfiConverterTypePlacesTimestamp.write(value.lastModified, into: buf) + FfiConverterOptionTypeGuid.write(value.parentGuid, into: buf) + FfiConverterUInt32.write(value.position, into: buf) + FfiConverterOptionString.write(value.title, into: buf) + FfiConverterOptionSequenceTypeGuid.write(value.childGuids, into: buf) + FfiConverterOptionSequenceTypeBookmarkItem.write(value.childNodes, into: buf) } } -extension BookmarkFolder: ViaFfiUsingByteBuffer, ViaFfi {} - public struct BookmarkUpdateInfo { - public var guid: String + public var guid: Guid public var title: String? public var url: String? - public var parentGuid: String? + public var parentGuid: Guid? public var position: UInt32? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(guid: String, title: String?, url: String?, parentGuid: String?, position: UInt32?) { + public init(guid: Guid, title: String?, url: String?, parentGuid: Guid?, position: UInt32?) { self.guid = guid self.title = title self.url = url @@ -2277,40 +2279,38 @@ extension BookmarkUpdateInfo: Equatable, Hashable { } } -private extension BookmarkUpdateInfo { - static func read(from buf: Reader) throws -> BookmarkUpdateInfo { +private struct FfiConverterTypeBookmarkUpdateInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> BookmarkUpdateInfo { return try BookmarkUpdateInfo( - guid: FfiConverterTypeGuid.read(buf), + guid: FfiConverterTypeGuid.read(from: buf), title: FfiConverterOptionString.read(from: buf), url: FfiConverterOptionString.read(from: buf), - parentGuid: FfiConverterOptionGuid.read(from: buf), + parentGuid: FfiConverterOptionTypeGuid.read(from: buf), position: FfiConverterOptionUInt32.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterTypeGuid.write(guid, buf) - FfiConverterOptionString.write(title, into: buf) - FfiConverterOptionString.write(url, into: buf) - FfiConverterOptionGuid.write(parentGuid, into: buf) - FfiConverterOptionUInt32.write(position, into: buf) + fileprivate static func write(_ value: BookmarkUpdateInfo, into buf: Writer) { + FfiConverterTypeGuid.write(value.guid, into: buf) + FfiConverterOptionString.write(value.title, into: buf) + FfiConverterOptionString.write(value.url, into: buf) + FfiConverterOptionTypeGuid.write(value.parentGuid, into: buf) + FfiConverterOptionUInt32.write(value.position, into: buf) } } -extension BookmarkUpdateInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct InsertableBookmark { - public var guid: String? - public var parentGuid: String + public var guid: Guid? + public var parentGuid: Guid public var position: BookmarkPosition - public var dateAdded: Int64? - public var lastModified: Int64? - public var url: String + public var dateAdded: PlacesTimestamp? + public var lastModified: PlacesTimestamp? + public var url: Url public var title: String? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(guid: String? = nil, parentGuid: String, position: BookmarkPosition, dateAdded: Int64? = nil, lastModified: Int64? = nil, url: String, title: String? = nil) { + public init(guid: Guid? = nil, parentGuid: Guid, position: BookmarkPosition, dateAdded: PlacesTimestamp? = nil, lastModified: PlacesTimestamp? = nil, url: Url, title: String? = nil) { self.guid = guid self.parentGuid = parentGuid self.position = position @@ -2358,42 +2358,40 @@ extension InsertableBookmark: Equatable, Hashable { } } -private extension InsertableBookmark { - static func read(from buf: Reader) throws -> InsertableBookmark { +private struct FfiConverterTypeInsertableBookmark: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> InsertableBookmark { return try InsertableBookmark( - guid: FfiConverterOptionGuid.read(from: buf), - parentGuid: FfiConverterTypeGuid.read(buf), - position: BookmarkPosition.read(from: buf), - dateAdded: FfiConverterOptionTimestamp.read(from: buf), - lastModified: FfiConverterOptionTimestamp.read(from: buf), - url: FfiConverterTypeUrl.read(buf), + guid: FfiConverterOptionTypeGuid.read(from: buf), + parentGuid: FfiConverterTypeGuid.read(from: buf), + position: FfiConverterTypeBookmarkPosition.read(from: buf), + dateAdded: FfiConverterOptionTypePlacesTimestamp.read(from: buf), + lastModified: FfiConverterOptionTypePlacesTimestamp.read(from: buf), + url: FfiConverterTypeUrl.read(from: buf), title: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterOptionGuid.write(guid, into: buf) - FfiConverterTypeGuid.write(parentGuid, buf) - position.write(into: buf) - FfiConverterOptionTimestamp.write(dateAdded, into: buf) - FfiConverterOptionTimestamp.write(lastModified, into: buf) - FfiConverterTypeUrl.write(url, buf) - FfiConverterOptionString.write(title, into: buf) + fileprivate static func write(_ value: InsertableBookmark, into buf: Writer) { + FfiConverterOptionTypeGuid.write(value.guid, into: buf) + FfiConverterTypeGuid.write(value.parentGuid, into: buf) + FfiConverterTypeBookmarkPosition.write(value.position, into: buf) + FfiConverterOptionTypePlacesTimestamp.write(value.dateAdded, into: buf) + FfiConverterOptionTypePlacesTimestamp.write(value.lastModified, into: buf) + FfiConverterTypeUrl.write(value.url, into: buf) + FfiConverterOptionString.write(value.title, into: buf) } } -extension InsertableBookmark: ViaFfiUsingByteBuffer, ViaFfi {} - public struct InsertableBookmarkSeparator { - public var guid: String? - public var parentGuid: String + public var guid: Guid? + public var parentGuid: Guid public var position: BookmarkPosition - public var dateAdded: Int64? - public var lastModified: Int64? + public var dateAdded: PlacesTimestamp? + public var lastModified: PlacesTimestamp? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(guid: String? = nil, parentGuid: String, position: BookmarkPosition, dateAdded: Int64? = nil, lastModified: Int64? = nil) { + public init(guid: Guid? = nil, parentGuid: Guid, position: BookmarkPosition, dateAdded: PlacesTimestamp? = nil, lastModified: PlacesTimestamp? = nil) { self.guid = guid self.parentGuid = parentGuid self.position = position @@ -2431,40 +2429,38 @@ extension InsertableBookmarkSeparator: Equatable, Hashable { } } -private extension InsertableBookmarkSeparator { - static func read(from buf: Reader) throws -> InsertableBookmarkSeparator { +private struct FfiConverterTypeInsertableBookmarkSeparator: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> InsertableBookmarkSeparator { return try InsertableBookmarkSeparator( - guid: FfiConverterOptionGuid.read(from: buf), - parentGuid: FfiConverterTypeGuid.read(buf), - position: BookmarkPosition.read(from: buf), - dateAdded: FfiConverterOptionTimestamp.read(from: buf), - lastModified: FfiConverterOptionTimestamp.read(from: buf) + guid: FfiConverterOptionTypeGuid.read(from: buf), + parentGuid: FfiConverterTypeGuid.read(from: buf), + position: FfiConverterTypeBookmarkPosition.read(from: buf), + dateAdded: FfiConverterOptionTypePlacesTimestamp.read(from: buf), + lastModified: FfiConverterOptionTypePlacesTimestamp.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterOptionGuid.write(guid, into: buf) - FfiConverterTypeGuid.write(parentGuid, buf) - position.write(into: buf) - FfiConverterOptionTimestamp.write(dateAdded, into: buf) - FfiConverterOptionTimestamp.write(lastModified, into: buf) + fileprivate static func write(_ value: InsertableBookmarkSeparator, into buf: Writer) { + FfiConverterOptionTypeGuid.write(value.guid, into: buf) + FfiConverterTypeGuid.write(value.parentGuid, into: buf) + FfiConverterTypeBookmarkPosition.write(value.position, into: buf) + FfiConverterOptionTypePlacesTimestamp.write(value.dateAdded, into: buf) + FfiConverterOptionTypePlacesTimestamp.write(value.lastModified, into: buf) } } -extension InsertableBookmarkSeparator: ViaFfiUsingByteBuffer, ViaFfi {} - public struct InsertableBookmarkFolder { - public var guid: String? - public var parentGuid: String + public var guid: Guid? + public var parentGuid: Guid public var position: BookmarkPosition - public var dateAdded: Int64? - public var lastModified: Int64? + public var dateAdded: PlacesTimestamp? + public var lastModified: PlacesTimestamp? public var title: String? public var children: [InsertableBookmarkItem] // Default memberwise initializers are never public by default, so we // declare one manually. - public init(guid: String? = nil, parentGuid: String, position: BookmarkPosition, dateAdded: Int64? = nil, lastModified: Int64? = nil, title: String? = nil, children: [InsertableBookmarkItem]) { + public init(guid: Guid? = nil, parentGuid: Guid, position: BookmarkPosition, dateAdded: PlacesTimestamp? = nil, lastModified: PlacesTimestamp? = nil, title: String? = nil, children: [InsertableBookmarkItem]) { self.guid = guid self.parentGuid = parentGuid self.position = position @@ -2512,32 +2508,30 @@ extension InsertableBookmarkFolder: Equatable, Hashable { } } -private extension InsertableBookmarkFolder { - static func read(from buf: Reader) throws -> InsertableBookmarkFolder { +private struct FfiConverterTypeInsertableBookmarkFolder: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> InsertableBookmarkFolder { return try InsertableBookmarkFolder( - guid: FfiConverterOptionGuid.read(from: buf), - parentGuid: FfiConverterTypeGuid.read(buf), - position: BookmarkPosition.read(from: buf), - dateAdded: FfiConverterOptionTimestamp.read(from: buf), - lastModified: FfiConverterOptionTimestamp.read(from: buf), + guid: FfiConverterOptionTypeGuid.read(from: buf), + parentGuid: FfiConverterTypeGuid.read(from: buf), + position: FfiConverterTypeBookmarkPosition.read(from: buf), + dateAdded: FfiConverterOptionTypePlacesTimestamp.read(from: buf), + lastModified: FfiConverterOptionTypePlacesTimestamp.read(from: buf), title: FfiConverterOptionString.read(from: buf), - children: FfiConverterSequenceEnumInsertableBookmarkItem.read(from: buf) + children: FfiConverterSequenceTypeInsertableBookmarkItem.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterOptionGuid.write(guid, into: buf) - FfiConverterTypeGuid.write(parentGuid, buf) - position.write(into: buf) - FfiConverterOptionTimestamp.write(dateAdded, into: buf) - FfiConverterOptionTimestamp.write(lastModified, into: buf) - FfiConverterOptionString.write(title, into: buf) - FfiConverterSequenceEnumInsertableBookmarkItem.write(children, into: buf) + fileprivate static func write(_ value: InsertableBookmarkFolder, into buf: Writer) { + FfiConverterOptionTypeGuid.write(value.guid, into: buf) + FfiConverterTypeGuid.write(value.parentGuid, into: buf) + FfiConverterTypeBookmarkPosition.write(value.position, into: buf) + FfiConverterOptionTypePlacesTimestamp.write(value.dateAdded, into: buf) + FfiConverterOptionTypePlacesTimestamp.write(value.lastModified, into: buf) + FfiConverterOptionString.write(value.title, into: buf) + FfiConverterSequenceTypeInsertableBookmarkItem.write(value.children, into: buf) } } -extension InsertableBookmarkFolder: ViaFfiUsingByteBuffer, ViaFfi {} - public enum PlacesError { // Simple error enums only carry a message case UnexpectedPlacesException(message: String) @@ -2576,100 +2570,102 @@ public enum PlacesError { case InternalError(message: String) } -extension PlacesError: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> PlacesError { +private struct FfiConverterTypePlacesError: FfiConverterRustBuffer { + typealias SwiftType = PlacesError + + static func read(from buf: Reader) throws -> PlacesError { let variant: Int32 = try buf.readInt() switch variant { case 1: return .UnexpectedPlacesException( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 2: return .UrlParseFailed( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 3: return .JsonParseFailed( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 4: return .PlacesConnectionBusy( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 5: return .OperationInterrupted( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 6: return .BookmarksCorruption( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 7: return .InvalidParent( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 8: return .UnknownBookmarkItem( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 9: return .UrlTooLong( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 10: return .InvalidBookmarkUpdate( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 11: return .CannotUpdateRoot( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 12: return .InternalError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: PlacesError, into buf: Writer) { + switch value { case let .UnexpectedPlacesException(message): buf.writeInt(Int32(1)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UrlParseFailed(message): buf.writeInt(Int32(2)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .JsonParseFailed(message): buf.writeInt(Int32(3)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .PlacesConnectionBusy(message): buf.writeInt(Int32(4)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .OperationInterrupted(message): buf.writeInt(Int32(5)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .BookmarksCorruption(message): buf.writeInt(Int32(6)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidParent(message): buf.writeInt(Int32(7)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UnknownBookmarkItem(message): buf.writeInt(Int32(8)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UrlTooLong(message): buf.writeInt(Int32(9)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidBookmarkUpdate(message): buf.writeInt(Int32(10)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .CannotUpdateRoot(message): buf.writeInt(Int32(11)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InternalError(message): buf.writeInt(Int32(12)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) } } } @@ -2677,154 +2673,124 @@ extension PlacesError: ViaFfiUsingByteBuffer, ViaFfi { extension PlacesError: Equatable, Hashable {} extension PlacesError: Error {} -private enum FfiConverterTypeGuid { - fileprivate static func read(_ buf: Reader) throws -> String { - return try String.read(from: buf) - } - - fileprivate static func write(_ value: String, _ buf: Writer) { - return value.write(into: buf) - } - fileprivate static func lift(_ value: RustBuffer) throws -> String { - return try String.lift(value) - } - - fileprivate static func lower(_ value: String) -> RustBuffer { - return value.lower() - } -} - -private enum FfiConverterTypeTimestamp { - fileprivate static func read(_ buf: Reader) throws -> Int64 { - return try Int64.read(from: buf) - } - - fileprivate static func write(_ value: Int64, _ buf: Writer) { - return value.write(into: buf) - } - - fileprivate static func lift(_ value: Int64) throws -> Int64 { - return try Int64.lift(value) - } +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias Guid = String +private typealias FfiConverterTypeGuid = FfiConverterString - fileprivate static func lower(_ value: Int64) -> Int64 { - return value.lower() - } -} +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias PlacesTimestamp = Int64 +private typealias FfiConverterTypePlacesTimestamp = FfiConverterInt64 -private enum FfiConverterTypeUrl { - fileprivate static func read(_ buf: Reader) throws -> String { - return try String.read(from: buf) - } +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias Url = String +private typealias FfiConverterTypeUrl = FfiConverterString - fileprivate static func write(_ value: String, _ buf: Writer) { - return value.write(into: buf) - } +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias VisitTransitionSet = Int32 +private typealias FfiConverterTypeVisitTransitionSet = FfiConverterInt32 +private struct FfiConverterUInt32: FfiConverterPrimitive { + typealias FfiType = UInt32 + typealias SwiftType = UInt32 - fileprivate static func lift(_ value: RustBuffer) throws -> String { - return try String.lift(value) + static func read(from buf: Reader) throws -> UInt32 { + return try lift(buf.readInt()) } - fileprivate static func lower(_ value: String) -> RustBuffer { - return value.lower() + static func write(_ value: SwiftType, into buf: Writer) { + buf.writeInt(lower(value)) } } -private enum FfiConverterTypeVisitTransitionSet { - fileprivate static func read(_ buf: Reader) throws -> Int32 { - return try Int32.read(from: buf) - } - - fileprivate static func write(_ value: Int32, _ buf: Writer) { - return value.write(into: buf) - } - - fileprivate static func lift(_ value: Int32) throws -> Int32 { - return try Int32.lift(value) - } - - fileprivate static func lower(_ value: Int32) -> Int32 { - return value.lower() - } -} +private struct FfiConverterInt32: FfiConverterPrimitive { + typealias FfiType = Int32 + typealias SwiftType = Int32 -extension UInt32: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> Int32 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int32, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Int32: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { - return try lift(buf.readInt()) - } - - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) - } -} +private struct FfiConverterInt64: FfiConverterPrimitive { + typealias FfiType = Int64 + typealias SwiftType = Int64 -extension Int64: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> Int64 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int64, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Double: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterDouble: FfiConverterPrimitive { + typealias FfiType = Double + typealias SwiftType = Double + + static func read(from buf: Reader) throws -> Double { return try lift(buf.readDouble()) } - fileprivate func write(into buf: Writer) { - buf.writeDouble(lower()) + static func write(_ value: Double, into buf: Writer) { + buf.writeDouble(lower(value)) } } -extension Bool: ViaFfi { - fileprivate typealias FfiType = Int8 +private struct FfiConverterBool: FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool - fileprivate static func read(from buf: Reader) throws -> Self { - return try lift(buf.readInt()) + static func lift(_ value: Int8) throws -> Bool { + return value != 0 } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 } - fileprivate static func lift(_ v: FfiType) throws -> Self { - return v != 0 + static func read(from buf: Reader) throws -> Bool { + return try lift(buf.readInt()) } - fileprivate func lower() -> FfiType { - return self ? 1 : 0 + static func write(_ value: Bool, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension String: ViaFfi { - fileprivate typealias FfiType = RustBuffer +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer - fileprivate static func lift(_ v: FfiType) throws -> Self { + static func lift(_ value: RustBuffer) throws -> String { defer { - v.deallocate() + value.deallocate() } - if v.data == nil { + if value.data == nil { return String() } - let bytes = UnsafeBufferPointer(start: v.data!, count: Int(v.len)) + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) return String(bytes: bytes, encoding: String.Encoding.utf8)! } - fileprivate func lower() -> FfiType { - return utf8CString.withUnsafeBufferPointer { ptr in + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in // The swift string gives us int8_t, we want uint8_t. ptr.withMemoryRebound(to: UInt8.self) { ptr in // The swift string gives us a trailing null byte, we don't want it. @@ -2834,15 +2800,15 @@ extension String: ViaFfi { } } - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> String { let len: Int32 = try buf.readInt() return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! } - fileprivate func write(into buf: Writer) { - let len = Int32(utf8.count) + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) buf.writeInt(len) - buf.writeBytes(utf8) + buf.writeBytes(value.utf8) } } @@ -2876,424 +2842,566 @@ extension String: ViaFfi { // Helper code for VisitTransition enum is found in EnumTemplate.swift // Helper code for PlacesError error is found in ErrorTemplate.swift -private enum FfiConverterOptionUInt32: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionUInt32: FfiConverterRustBuffer { typealias SwiftType = UInt32? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterUInt32.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try UInt32.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt32.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionInt32: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionInt32: FfiConverterRustBuffer { typealias SwiftType = Int32? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterInt32.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try Int32.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterInt32.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionBool: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionBool: FfiConverterRustBuffer { typealias SwiftType = Bool? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterBool.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try Bool.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterBool.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try String.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordHistoryMetadata: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeHistoryMetadata: FfiConverterRustBuffer { typealias SwiftType = HistoryMetadata? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeHistoryMetadata.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try HistoryMetadata.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeHistoryMetadata.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionEnumBookmarkItem: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeBookmarkItem: FfiConverterRustBuffer { typealias SwiftType = BookmarkItem? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeBookmarkItem.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try BookmarkItem.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeBookmarkItem.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionEnumDocumentType: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeDocumentType: FfiConverterRustBuffer { typealias SwiftType = DocumentType? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeDocumentType.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try DocumentType.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeDocumentType.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionEnumVisitTransition: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeVisitTransition: FfiConverterRustBuffer { typealias SwiftType = VisitTransition? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeVisitTransition.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try VisitTransition.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeVisitTransition.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionSequenceRecordHistoryMetadata: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionSequenceTypeHistoryMetadata: FfiConverterRustBuffer { typealias SwiftType = [HistoryMetadata]? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterSequenceRecordHistoryMetadata.write(item, into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterSequenceTypeHistoryMetadata.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterSequenceRecordHistoryMetadata.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterSequenceTypeHistoryMetadata.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionSequenceEnumBookmarkItem: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionSequenceTypeBookmarkItem: FfiConverterRustBuffer { typealias SwiftType = [BookmarkItem]? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterSequenceEnumBookmarkItem.write(item, into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterSequenceTypeBookmarkItem.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterSequenceEnumBookmarkItem.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterSequenceTypeBookmarkItem.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionSequenceGuid: FfiConverterUsingByteBuffer { - typealias SwiftType = [String]? +private struct FfiConverterOptionSequenceTypeGuid: FfiConverterRustBuffer { + typealias SwiftType = [Guid]? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterSequenceGuid.write(item, into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterSequenceTypeGuid.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterSequenceGuid.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterSequenceTypeGuid.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionGuid: FfiConverterUsingByteBuffer { - typealias SwiftType = String? +private struct FfiConverterOptionTypeGuid: FfiConverterRustBuffer { + typealias SwiftType = Guid? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterTypeGuid.write(item, buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeGuid.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterTypeGuid.read(buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeGuid.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionTimestamp: FfiConverterUsingByteBuffer { - typealias SwiftType = Int64? +private struct FfiConverterOptionTypePlacesTimestamp: FfiConverterRustBuffer { + typealias SwiftType = PlacesTimestamp? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterTypeTimestamp.write(item, buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypePlacesTimestamp.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterTypeTimestamp.read(buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypePlacesTimestamp.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionUrl: FfiConverterUsingByteBuffer { - typealias SwiftType = String? +private struct FfiConverterOptionTypeUrl: FfiConverterRustBuffer { + typealias SwiftType = Url? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterTypeUrl.write(item, buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeUrl.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterTypeUrl.read(buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeUrl.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterSequenceBool: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceBool: FfiConverterRustBuffer { typealias SwiftType = [Bool] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [Bool], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterBool.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try Bool.read(from: buf) + static func read(from buf: Reader) throws -> [Bool] { + let len: Int32 = try buf.readInt() + var seq = [Bool]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterBool.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceString: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterString.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try String.read(from: buf) + static func read(from buf: Reader) throws -> [String] { + let len: Int32 = try buf.readInt() + var seq = [String]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterString.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordHistoryHighlight: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeHistoryHighlight: FfiConverterRustBuffer { typealias SwiftType = [HistoryHighlight] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [HistoryHighlight], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeHistoryHighlight.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try HistoryHighlight.read(from: buf) + static func read(from buf: Reader) throws -> [HistoryHighlight] { + let len: Int32 = try buf.readInt() + var seq = [HistoryHighlight]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeHistoryHighlight.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordHistoryMetadata: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeHistoryMetadata: FfiConverterRustBuffer { typealias SwiftType = [HistoryMetadata] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [HistoryMetadata], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeHistoryMetadata.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try HistoryMetadata.read(from: buf) + static func read(from buf: Reader) throws -> [HistoryMetadata] { + let len: Int32 = try buf.readInt() + var seq = [HistoryMetadata]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeHistoryMetadata.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordHistoryVisitInfo: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeHistoryVisitInfo: FfiConverterRustBuffer { typealias SwiftType = [HistoryVisitInfo] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [HistoryVisitInfo], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeHistoryVisitInfo.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try HistoryVisitInfo.read(from: buf) + static func read(from buf: Reader) throws -> [HistoryVisitInfo] { + let len: Int32 = try buf.readInt() + var seq = [HistoryVisitInfo]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeHistoryVisitInfo.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordSearchResult: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeSearchResult: FfiConverterRustBuffer { typealias SwiftType = [SearchResult] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [SearchResult], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeSearchResult.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try SearchResult.read(from: buf) + static func read(from buf: Reader) throws -> [SearchResult] { + let len: Int32 = try buf.readInt() + var seq = [SearchResult]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeSearchResult.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordTopFrecentSiteInfo: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeTopFrecentSiteInfo: FfiConverterRustBuffer { typealias SwiftType = [TopFrecentSiteInfo] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [TopFrecentSiteInfo], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeTopFrecentSiteInfo.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try TopFrecentSiteInfo.read(from: buf) + static func read(from buf: Reader) throws -> [TopFrecentSiteInfo] { + let len: Int32 = try buf.readInt() + var seq = [TopFrecentSiteInfo]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeTopFrecentSiteInfo.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceEnumBookmarkItem: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeBookmarkItem: FfiConverterRustBuffer { typealias SwiftType = [BookmarkItem] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [BookmarkItem], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeBookmarkItem.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try BookmarkItem.read(from: buf) + static func read(from buf: Reader) throws -> [BookmarkItem] { + let len: Int32 = try buf.readInt() + var seq = [BookmarkItem]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeBookmarkItem.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceEnumInsertableBookmarkItem: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeInsertableBookmarkItem: FfiConverterRustBuffer { typealias SwiftType = [InsertableBookmarkItem] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [InsertableBookmarkItem], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeInsertableBookmarkItem.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try InsertableBookmarkItem.read(from: buf) + static func read(from buf: Reader) throws -> [InsertableBookmarkItem] { + let len: Int32 = try buf.readInt() + var seq = [InsertableBookmarkItem]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeInsertableBookmarkItem.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceEnumMatchReason: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeMatchReason: FfiConverterRustBuffer { typealias SwiftType = [MatchReason] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [MatchReason], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeMatchReason.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try MatchReason.read(from: buf) + static func read(from buf: Reader) throws -> [MatchReason] { + let len: Int32 = try buf.readInt() + var seq = [MatchReason]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeMatchReason.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceGuid: FfiConverterUsingByteBuffer { - typealias SwiftType = [String] +private struct FfiConverterSequenceTypeGuid: FfiConverterRustBuffer { + typealias SwiftType = [Guid] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - FfiConverterTypeGuid.write(item, buf) + static func write(_ value: [Guid], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeGuid.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try FfiConverterTypeGuid.read(buf) + static func read(from buf: Reader) throws -> [Guid] { + let len: Int32 = try buf.readInt() + var seq = [Guid]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeGuid.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceUrl: FfiConverterUsingByteBuffer { - typealias SwiftType = [String] +private struct FfiConverterSequenceTypeUrl: FfiConverterRustBuffer { + typealias SwiftType = [Url] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - FfiConverterTypeUrl.write(item, buf) + static func write(_ value: [Url], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeUrl.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try FfiConverterTypeUrl.read(buf) + static func read(from buf: Reader) throws -> [Url] { + let len: Int32 = try buf.readInt() + var seq = [Url]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeUrl.read(from: buf)) } + return seq } } // Helper code for Guid is found in CustomType.py -// Helper code for Timestamp is found in CustomType.py +// Helper code for PlacesTimestamp is found in CustomType.py // Helper code for Url is found in CustomType.py // Helper code for VisitTransitionSet is found in CustomType.py diff --git a/swift-source/all/Generated/placesFFI.h b/swift-source/all/Generated/placesFFI.h index 23def836..c4fffd25 100644 --- a/swift-source/all/Generated/placesFFI.h +++ b/swift-source/all/Generated/placesFFI.h @@ -46,227 +46,227 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_places_4240_SqlInterruptHandle_object_free( +void ffi_places_56cb_SqlInterruptHandle_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void places_4240_SqlInterruptHandle_interrupt( +void places_56cb_SqlInterruptHandle_interrupt( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void ffi_places_4240_PlacesApi_object_free( +void ffi_places_56cb_PlacesApi_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull places_4240_PlacesApi_new_connection( +void*_Nonnull places_56cb_PlacesApi_new_connection( void*_Nonnull ptr,RustBuffer conn_type, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesApi_register_with_sync_manager( +void places_56cb_PlacesApi_register_with_sync_manager( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesApi_reset_history( +void places_56cb_PlacesApi_reset_history( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesApi_history_sync( +RustBuffer places_56cb_PlacesApi_history_sync( void*_Nonnull ptr,RustBuffer key_id,RustBuffer access_token,RustBuffer sync_key,RustBuffer tokenserver_url, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesApi_bookmarks_sync( +RustBuffer places_56cb_PlacesApi_bookmarks_sync( void*_Nonnull ptr,RustBuffer key_id,RustBuffer access_token,RustBuffer sync_key,RustBuffer tokenserver_url, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesApi_places_pinned_sites_import_from_fennec( +RustBuffer places_56cb_PlacesApi_places_pinned_sites_import_from_fennec( void*_Nonnull ptr,RustBuffer db_path, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesApi_places_history_import_from_fennec( +RustBuffer places_56cb_PlacesApi_places_history_import_from_fennec( void*_Nonnull ptr,RustBuffer db_path, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesApi_places_bookmarks_import_from_fennec( +RustBuffer places_56cb_PlacesApi_places_bookmarks_import_from_fennec( void*_Nonnull ptr,RustBuffer db_path, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesApi_places_bookmarks_import_from_ios( +void places_56cb_PlacesApi_places_bookmarks_import_from_ios( void*_Nonnull ptr,RustBuffer db_path, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesApi_bookmarks_reset( +void places_56cb_PlacesApi_bookmarks_reset( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void ffi_places_4240_PlacesConnection_object_free( +void ffi_places_56cb_PlacesConnection_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull places_4240_PlacesConnection_new_interrupt_handle( +void*_Nonnull places_56cb_PlacesConnection_new_interrupt_handle( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_latest_history_metadata_for_url( +RustBuffer places_56cb_PlacesConnection_get_latest_history_metadata_for_url( void*_Nonnull ptr,RustBuffer url, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_history_metadata_between( +RustBuffer places_56cb_PlacesConnection_get_history_metadata_between( void*_Nonnull ptr,int64_t start,int64_t end, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_history_metadata_since( +RustBuffer places_56cb_PlacesConnection_get_history_metadata_since( void*_Nonnull ptr,int64_t since, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_query_autocomplete( +RustBuffer places_56cb_PlacesConnection_query_autocomplete( void*_Nonnull ptr,RustBuffer search,int32_t limit, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_accept_result( +void places_56cb_PlacesConnection_accept_result( void*_Nonnull ptr,RustBuffer search_string,RustBuffer url, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_match_url( +RustBuffer places_56cb_PlacesConnection_match_url( void*_Nonnull ptr,RustBuffer query, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_query_history_metadata( +RustBuffer places_56cb_PlacesConnection_query_history_metadata( void*_Nonnull ptr,RustBuffer query,int32_t limit, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_history_highlights( +RustBuffer places_56cb_PlacesConnection_get_history_highlights( void*_Nonnull ptr,RustBuffer weights,int32_t limit, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_note_history_metadata_observation( +void places_56cb_PlacesConnection_note_history_metadata_observation( void*_Nonnull ptr,RustBuffer data, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_metadata_delete( +void places_56cb_PlacesConnection_metadata_delete( void*_Nonnull ptr,RustBuffer url,RustBuffer referrer_url,RustBuffer search_term, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_metadata_delete_older_than( +void places_56cb_PlacesConnection_metadata_delete_older_than( void*_Nonnull ptr,int64_t older_than, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_apply_observation( +void places_56cb_PlacesConnection_apply_observation( void*_Nonnull ptr,RustBuffer visit, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_visited_urls_in_range( +RustBuffer places_56cb_PlacesConnection_get_visited_urls_in_range( void*_Nonnull ptr,int64_t start,int64_t end,int8_t include_remote, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_visit_infos( +RustBuffer places_56cb_PlacesConnection_get_visit_infos( void*_Nonnull ptr,int64_t start_date,int64_t end_date,int32_t exclude_types, RustCallStatus *_Nonnull out_status ); -int64_t places_4240_PlacesConnection_get_visit_count( +int64_t places_56cb_PlacesConnection_get_visit_count( void*_Nonnull ptr,int32_t exclude_types, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_visit_page( +RustBuffer places_56cb_PlacesConnection_get_visit_page( void*_Nonnull ptr,int64_t offset,int64_t count,int32_t exclude_types, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_visit_page_with_bound( +RustBuffer places_56cb_PlacesConnection_get_visit_page_with_bound( void*_Nonnull ptr,int64_t bound,int64_t offset,int64_t count,int32_t exclude_types, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_visited( +RustBuffer places_56cb_PlacesConnection_get_visited( void*_Nonnull ptr,RustBuffer urls, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_delete_visits_for( +void places_56cb_PlacesConnection_delete_visits_for( void*_Nonnull ptr,RustBuffer url, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_delete_visits_between( +void places_56cb_PlacesConnection_delete_visits_between( void*_Nonnull ptr,int64_t start,int64_t end, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_delete_visit( +void places_56cb_PlacesConnection_delete_visit( void*_Nonnull ptr,RustBuffer url,int64_t timestamp, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_get_top_frecent_site_infos( +RustBuffer places_56cb_PlacesConnection_get_top_frecent_site_infos( void*_Nonnull ptr,int32_t num_items,RustBuffer threshold_option, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_wipe_local_history( +void places_56cb_PlacesConnection_wipe_local_history( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_delete_everything_history( +void places_56cb_PlacesConnection_delete_everything_history( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_prune_destructively( +void places_56cb_PlacesConnection_prune_destructively( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_run_maintenance( +void places_56cb_PlacesConnection_run_maintenance( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_bookmarks_get_tree( +RustBuffer places_56cb_PlacesConnection_bookmarks_get_tree( void*_Nonnull ptr,RustBuffer item_guid, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_bookmarks_get_by_guid( +RustBuffer places_56cb_PlacesConnection_bookmarks_get_by_guid( void*_Nonnull ptr,RustBuffer guid,int8_t get_direct_children, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_bookmarks_get_all_with_url( +RustBuffer places_56cb_PlacesConnection_bookmarks_get_all_with_url( void*_Nonnull ptr,RustBuffer url, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_bookmarks_search( +RustBuffer places_56cb_PlacesConnection_bookmarks_search( void*_Nonnull ptr,RustBuffer query,int32_t limit, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_bookmarks_get_recent( +RustBuffer places_56cb_PlacesConnection_bookmarks_get_recent( void*_Nonnull ptr,int32_t limit, RustCallStatus *_Nonnull out_status ); -int8_t places_4240_PlacesConnection_bookmarks_delete( +int8_t places_56cb_PlacesConnection_bookmarks_delete( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_bookmarks_delete_everything( +void places_56cb_PlacesConnection_bookmarks_delete_everything( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_bookmarks_get_url_for_keyword( +RustBuffer places_56cb_PlacesConnection_bookmarks_get_url_for_keyword( void*_Nonnull ptr,RustBuffer keyword, RustCallStatus *_Nonnull out_status ); -void places_4240_PlacesConnection_bookmarks_update( +void places_56cb_PlacesConnection_bookmarks_update( void*_Nonnull ptr,RustBuffer data, RustCallStatus *_Nonnull out_status ); -RustBuffer places_4240_PlacesConnection_bookmarks_insert( +RustBuffer places_56cb_PlacesConnection_bookmarks_insert( void*_Nonnull ptr,RustBuffer bookmark, RustCallStatus *_Nonnull out_status ); -void*_Nonnull places_4240_places_api_new( +void*_Nonnull places_56cb_places_api_new( RustBuffer db_path, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_places_4240_rustbuffer_alloc( +RustBuffer ffi_places_56cb_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_places_4240_rustbuffer_from_bytes( +RustBuffer ffi_places_56cb_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_places_4240_rustbuffer_free( +void ffi_places_56cb_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_places_4240_rustbuffer_reserve( +RustBuffer ffi_places_56cb_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/swift-source/all/Generated/push.swift b/swift-source/all/Generated/push.swift index 87e6b3ce..9534fbf1 100644 --- a/swift-source/all/Generated/push.swift +++ b/swift-source/all/Generated/push.swift @@ -19,13 +19,13 @@ private extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_push_f28b_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_push_db7d_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_push_f28b_rustbuffer_free(self, $0) } + try! rustCall { ffi_push_db7d_rustbuffer_free(self, $0) } } } @@ -147,45 +147,39 @@ private class Writer { } } -// Types conforming to `Serializable` can be read and written in a bytebuffer. -private protocol Serializable { - func write(into: Writer) - static func read(from: Reader) throws -> Self -} - -// Types confirming to `ViaFfi` can be transferred back-and-for over the FFI. -// This is analogous to the Rust trait of the same name. -private protocol ViaFfi: Serializable { +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { associatedtype FfiType - static func lift(_ v: FfiType) throws -> Self - func lower() -> FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol Primitive {} - -private extension Primitive { - typealias FfiType = Self +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} - static func lift(_ v: Self) throws -> Self { - return v +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value } - func lower() -> Self { - return self + static func lower(_ value: SwiftType) -> FfiType { + return value } } -// Types conforming to `ViaFfiUsingByteBuffer` lift and lower into a bytebuffer. -// Use this for complex types where it's hard to write a custom lift/lower. -private protocol ViaFfiUsingByteBuffer: Serializable {} - -private extension ViaFfiUsingByteBuffer { - typealias FfiType = RustBuffer +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - static func lift(_ buf: FfiType) throws -> Self { +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) + let value = try read(from: reader) if reader.hasRemaining() { throw UniffiInternalError.incompleteData } @@ -193,9 +187,9 @@ private extension ViaFfiUsingByteBuffer { return value } - func lower() -> FfiType { + static func lower(_ value: SwiftType) -> RustBuffer { let writer = Writer() - write(into: writer) + write(value, into: writer) return RustBuffer(bytes: writer.bytes) } } @@ -252,8 +246,11 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T }) } -private func rustCallWithError(_: E.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: { try E.lift($0) }) +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { @@ -271,7 +268,7 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) // with the message. But if that code panics, then it just sends back // an empty buffer. if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try String.lift(callStatus.errorBuf)) + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) } else { callStatus.errorBuf.deallocate() throw UniffiInternalError.rustPanic("Rust panic") @@ -282,103 +279,6 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -// Protocols for converters we'll implement in templates - -private protocol FfiConverter { - associatedtype SwiftType - associatedtype FfiType - - static func lift(_ ffiValue: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - - static func read(from: Reader) throws -> SwiftType - static func write(_ value: SwiftType, into: Writer) -} - -private protocol FfiConverterUsingByteBuffer: FfiConverter where FfiType == RustBuffer { - // Empty, because we want to declare some helper methods in the extension below. -} - -extension FfiConverterUsingByteBuffer { - static func lower(_ value: SwiftType) -> FfiType { - let writer = Writer() - Self.write(value, into: writer) - return RustBuffer(bytes: writer.bytes) - } - - static func lift(_ buf: FfiType) throws -> SwiftType { - let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) - if reader.hasRemaining() { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } -} - -// Helpers for structural types. Note that because of canonical_names, it /should/ be impossible -// to make another `FfiConverterSequence` etc just using the UDL. -private enum FfiConverterSequence { - static func write(_ value: [T], into buf: Writer, writeItem: (T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for item in value { - writeItem(item, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> [T] { - let len: Int32 = try buf.readInt() - var seq = [T]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try readItem(buf)) - } - return seq - } -} - -private enum FfiConverterOptional { - static func write(_ value: T?, into buf: Writer, writeItem: (T, Writer) -> Void) { - guard let value = value else { - buf.writeInt(Int8(0)) - return - } - buf.writeInt(Int8(1)) - writeItem(value, buf) - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> T? { - switch try buf.readInt() as Int8 { - case 0: return nil - case 1: return try readItem(buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -private enum FfiConverterDictionary { - static func write(_ value: [String: T], into buf: Writer, writeItem: (String, T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for (key, value) in value { - writeItem(key, value, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> (String, T)) throws -> [String: T] { - let len: Int32 = try buf.readInt() - var dict = [String: T]() - dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { - let (key, value) = try readItem(buf) - dict[key] = value - } - return dict - } -} - // Public interface members begin here. // Note that we don't yet support `indirect` for enums. @@ -391,20 +291,26 @@ public enum BridgeType { case test } -extension BridgeType: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> BridgeType { +private struct FfiConverterTypeBridgeType: FfiConverterRustBuffer { + typealias SwiftType = BridgeType + + static func read(from buf: Reader) throws -> BridgeType { let variant: Int32 = try buf.readInt() switch variant { case 1: return .fcm + case 2: return .adm + case 3: return .apns + case 4: return .test + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: BridgeType, into buf: Writer) { + switch value { case .fcm: buf.writeInt(Int32(1)) @@ -436,7 +342,7 @@ public class PushManager: PushManagerProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer @@ -445,75 +351,100 @@ public class PushManager: PushManagerProtocol { public convenience init(senderId: String, serverHost: String = "updates.push.services.mozilla.com", httpProtocol: String = "https", bridgeType: BridgeType, registrationId: String = "", databasePath: String = "push.sqlite") throws { self.init(unsafeFromRawPointer: try - rustCallWithError(PushError.self) { - push_f28b_PushManager_new(senderId.lower(), serverHost.lower(), httpProtocol.lower(), bridgeType.lower(), registrationId.lower(), databasePath.lower(), $0) + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_new( + FfiConverterString.lower(senderId), + FfiConverterString.lower(serverHost), + FfiConverterString.lower(httpProtocol), + FfiConverterTypeBridgeType.lower(bridgeType), + FfiConverterString.lower(registrationId), + FfiConverterString.lower(databasePath), $0 + ) }) } deinit { - try! rustCall { ffi_push_f28b_PushManager_object_free(pointer, $0) } + try! rustCall { ffi_push_db7d_PushManager_object_free(pointer, $0) } } public func subscribe(channelId: String = "", scope: String = "", appServerSey: String? = nil) throws -> SubscriptionResponse { - let _retval = try - rustCallWithError(PushError.self) { - push_f28b_PushManager_subscribe(self.pointer, channelId.lower(), scope.lower(), FfiConverterOptionString.lower(appServerSey), $0) - } - return try SubscriptionResponse.lift(_retval) + return try FfiConverterTypeSubscriptionResponse.lift( + try + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_subscribe(self.pointer, + FfiConverterString.lower(channelId), + FfiConverterString.lower(scope), + FfiConverterOptionString.lower(appServerSey), $0) + } + ) } public func unsubscribe(channelId: String) throws -> Bool { - let _retval = try - rustCallWithError(PushError.self) { - push_f28b_PushManager_unsubscribe(self.pointer, channelId.lower(), $0) - } - return try Bool.lift(_retval) + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_unsubscribe(self.pointer, + FfiConverterString.lower(channelId), $0) + } + ) } public func unsubscribeAll() throws { try - rustCallWithError(PushError.self) { - push_f28b_PushManager_unsubscribe_all(self.pointer, $0) + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_unsubscribe_all(self.pointer, $0) } } public func update(registrationToken: String) throws -> Bool { - let _retval = try - rustCallWithError(PushError.self) { - push_f28b_PushManager_update(self.pointer, registrationToken.lower(), $0) - } - return try Bool.lift(_retval) + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_update(self.pointer, + FfiConverterString.lower(registrationToken), $0) + } + ) } public func verifyConnection() throws -> [PushSubscriptionChanged] { - let _retval = try - rustCallWithError(PushError.self) { - push_f28b_PushManager_verify_connection(self.pointer, $0) - } - return try FfiConverterSequenceRecordPushSubscriptionChanged.lift(_retval) + return try FfiConverterSequenceTypePushSubscriptionChanged.lift( + try + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_verify_connection(self.pointer, $0) + } + ) } public func decrypt(channelId: String, body: String, encoding: String = "aes128gcm", salt: String = "", dh: String = "") throws -> [Int8] { - let _retval = try - rustCallWithError(PushError.self) { - push_f28b_PushManager_decrypt(self.pointer, channelId.lower(), body.lower(), encoding.lower(), salt.lower(), dh.lower(), $0) - } - return try FfiConverterSequenceInt8.lift(_retval) + return try FfiConverterSequenceInt8.lift( + try + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_decrypt(self.pointer, + FfiConverterString.lower(channelId), + FfiConverterString.lower(body), + FfiConverterString.lower(encoding), + FfiConverterString.lower(salt), + FfiConverterString.lower(dh), $0) + } + ) } public func dispatchInfoForChid(channelId: String) throws -> DispatchInfo? { - let _retval = try - rustCallWithError(PushError.self) { - push_f28b_PushManager_dispatch_info_for_chid(self.pointer, channelId.lower(), $0) - } - return try FfiConverterOptionRecordDispatchInfo.lift(_retval) + return try FfiConverterOptionTypeDispatchInfo.lift( + try + rustCallWithError(FfiConverterTypePushError.self) { + push_db7d_PushManager_dispatch_info_for_chid(self.pointer, + FfiConverterString.lower(channelId), $0) + } + ) } } -private extension PushManager { +private struct FfiConverterTypePushManager: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = PushManager - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> PushManager { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -524,27 +455,21 @@ private extension PushManager { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: PushManager, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PushManager { + return PushManager(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: PushManager) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension PushManager: ViaFfi, Serializable {} - public struct DispatchInfo { public var scope: String public var endpoint: String @@ -580,24 +505,22 @@ extension DispatchInfo: Equatable, Hashable { } } -private extension DispatchInfo { - static func read(from buf: Reader) throws -> DispatchInfo { +private struct FfiConverterTypeDispatchInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> DispatchInfo { return try DispatchInfo( - scope: String.read(from: buf), - endpoint: String.read(from: buf), + scope: FfiConverterString.read(from: buf), + endpoint: FfiConverterString.read(from: buf), appServerKey: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - scope.write(into: buf) - endpoint.write(into: buf) - FfiConverterOptionString.write(appServerKey, into: buf) + fileprivate static func write(_ value: DispatchInfo, into buf: Writer) { + FfiConverterString.write(value.scope, into: buf) + FfiConverterString.write(value.endpoint, into: buf) + FfiConverterOptionString.write(value.appServerKey, into: buf) } } -extension DispatchInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct KeyInfo { public var auth: String public var p256dh: String @@ -627,22 +550,20 @@ extension KeyInfo: Equatable, Hashable { } } -private extension KeyInfo { - static func read(from buf: Reader) throws -> KeyInfo { +private struct FfiConverterTypeKeyInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> KeyInfo { return try KeyInfo( - auth: String.read(from: buf), - p256dh: String.read(from: buf) + auth: FfiConverterString.read(from: buf), + p256dh: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - auth.write(into: buf) - p256dh.write(into: buf) + fileprivate static func write(_ value: KeyInfo, into buf: Writer) { + FfiConverterString.write(value.auth, into: buf) + FfiConverterString.write(value.p256dh, into: buf) } } -extension KeyInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct SubscriptionInfo { public var endpoint: String public var keys: KeyInfo @@ -672,22 +593,20 @@ extension SubscriptionInfo: Equatable, Hashable { } } -private extension SubscriptionInfo { - static func read(from buf: Reader) throws -> SubscriptionInfo { +private struct FfiConverterTypeSubscriptionInfo: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> SubscriptionInfo { return try SubscriptionInfo( - endpoint: String.read(from: buf), - keys: KeyInfo.read(from: buf) + endpoint: FfiConverterString.read(from: buf), + keys: FfiConverterTypeKeyInfo.read(from: buf) ) } - func write(into buf: Writer) { - endpoint.write(into: buf) - keys.write(into: buf) + fileprivate static func write(_ value: SubscriptionInfo, into buf: Writer) { + FfiConverterString.write(value.endpoint, into: buf) + FfiConverterTypeKeyInfo.write(value.keys, into: buf) } } -extension SubscriptionInfo: ViaFfiUsingByteBuffer, ViaFfi {} - public struct SubscriptionResponse { public var channelId: String public var subscriptionInfo: SubscriptionInfo @@ -717,22 +636,20 @@ extension SubscriptionResponse: Equatable, Hashable { } } -private extension SubscriptionResponse { - static func read(from buf: Reader) throws -> SubscriptionResponse { +private struct FfiConverterTypeSubscriptionResponse: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> SubscriptionResponse { return try SubscriptionResponse( - channelId: String.read(from: buf), - subscriptionInfo: SubscriptionInfo.read(from: buf) + channelId: FfiConverterString.read(from: buf), + subscriptionInfo: FfiConverterTypeSubscriptionInfo.read(from: buf) ) } - func write(into buf: Writer) { - channelId.write(into: buf) - subscriptionInfo.write(into: buf) + fileprivate static func write(_ value: SubscriptionResponse, into buf: Writer) { + FfiConverterString.write(value.channelId, into: buf) + FfiConverterTypeSubscriptionInfo.write(value.subscriptionInfo, into: buf) } } -extension SubscriptionResponse: ViaFfiUsingByteBuffer, ViaFfi {} - public struct PushSubscriptionChanged { public var channelId: String public var scope: String @@ -762,22 +679,20 @@ extension PushSubscriptionChanged: Equatable, Hashable { } } -private extension PushSubscriptionChanged { - static func read(from buf: Reader) throws -> PushSubscriptionChanged { +private struct FfiConverterTypePushSubscriptionChanged: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> PushSubscriptionChanged { return try PushSubscriptionChanged( - channelId: String.read(from: buf), - scope: String.read(from: buf) + channelId: FfiConverterString.read(from: buf), + scope: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - channelId.write(into: buf) - scope.write(into: buf) + fileprivate static func write(_ value: PushSubscriptionChanged, into buf: Writer) { + FfiConverterString.write(value.channelId, into: buf) + FfiConverterString.write(value.scope, into: buf) } } -extension PushSubscriptionChanged: ViaFfiUsingByteBuffer, ViaFfi {} - public enum PushError { // Simple error enums only carry a message case GeneralError(message: String) @@ -825,121 +740,123 @@ public enum PushError { case OpenDatabaseError(message: String) } -extension PushError: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> PushError { +private struct FfiConverterTypePushError: FfiConverterRustBuffer { + typealias SwiftType = PushError + + static func read(from buf: Reader) throws -> PushError { let variant: Int32 = try buf.readInt() switch variant { case 1: return .GeneralError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 2: return .CryptoError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 3: return .CommunicationError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 4: return .CommunicationServerError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 5: return .AlreadyRegisteredError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 6: return .StorageError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 7: return .RecordNotFoundError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 8: return .StorageSqlError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 9: return .MissingRegistrationTokenError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 10: return .TranscodingError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 11: return .UrlParseError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 12: return .JsonDeserializeError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 13: return .UaidNotRecognizedError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 14: return .RequestError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 15: return .OpenDatabaseError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: PushError, into buf: Writer) { + switch value { case let .GeneralError(message): buf.writeInt(Int32(1)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .CryptoError(message): buf.writeInt(Int32(2)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .CommunicationError(message): buf.writeInt(Int32(3)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .CommunicationServerError(message): buf.writeInt(Int32(4)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .AlreadyRegisteredError(message): buf.writeInt(Int32(5)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .StorageError(message): buf.writeInt(Int32(6)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .RecordNotFoundError(message): buf.writeInt(Int32(7)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .StorageSqlError(message): buf.writeInt(Int32(8)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .MissingRegistrationTokenError(message): buf.writeInt(Int32(9)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .TranscodingError(message): buf.writeInt(Int32(10)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UrlParseError(message): buf.writeInt(Int32(11)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .JsonDeserializeError(message): buf.writeInt(Int32(12)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UaidNotRecognizedError(message): buf.writeInt(Int32(13)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .RequestError(message): buf.writeInt(Int32(14)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .OpenDatabaseError(message): buf.writeInt(Int32(15)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) } } } @@ -947,52 +864,57 @@ extension PushError: ViaFfiUsingByteBuffer, ViaFfi { extension PushError: Equatable, Hashable {} extension PushError: Error {} -extension Int8: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterInt8: FfiConverterPrimitive { + typealias FfiType = Int8 + typealias SwiftType = Int8 + + static func read(from buf: Reader) throws -> Int8 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int8, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Bool: ViaFfi { - fileprivate typealias FfiType = Int8 +private struct FfiConverterBool: FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool - fileprivate static func read(from buf: Reader) throws -> Self { - return try lift(buf.readInt()) + static func lift(_ value: Int8) throws -> Bool { + return value != 0 } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 } - fileprivate static func lift(_ v: FfiType) throws -> Self { - return v != 0 + static func read(from buf: Reader) throws -> Bool { + return try lift(buf.readInt()) } - fileprivate func lower() -> FfiType { - return self ? 1 : 0 + static func write(_ value: Bool, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension String: ViaFfi { - fileprivate typealias FfiType = RustBuffer +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer - fileprivate static func lift(_ v: FfiType) throws -> Self { + static func lift(_ value: RustBuffer) throws -> String { defer { - v.deallocate() + value.deallocate() } - if v.data == nil { + if value.data == nil { return String() } - let bytes = UnsafeBufferPointer(start: v.data!, count: Int(v.len)) + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) return String(bytes: bytes, encoding: String.Encoding.utf8)! } - fileprivate func lower() -> FfiType { - return utf8CString.withUnsafeBufferPointer { ptr in + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in // The swift string gives us int8_t, we want uint8_t. ptr.withMemoryRebound(to: UInt8.self) { ptr in // The swift string gives us a trailing null byte, we don't want it. @@ -1002,15 +924,15 @@ extension String: ViaFfi { } } - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> String { let len: Int32 = try buf.readInt() return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! } - fileprivate func write(into buf: Writer) { - let len = Int32(utf8.count) + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) buf.writeInt(len) - buf.writeBytes(utf8) + buf.writeBytes(value.utf8) } } @@ -1023,67 +945,89 @@ extension String: ViaFfi { // Helper code for BridgeType enum is found in EnumTemplate.swift // Helper code for PushError error is found in ErrorTemplate.swift -private enum FfiConverterOptionString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try String.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordDispatchInfo: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeDispatchInfo: FfiConverterRustBuffer { typealias SwiftType = DispatchInfo? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeDispatchInfo.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try DispatchInfo.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeDispatchInfo.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterSequenceInt8: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceInt8: FfiConverterRustBuffer { typealias SwiftType = [Int8] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [Int8], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterInt8.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try Int8.read(from: buf) + static func read(from buf: Reader) throws -> [Int8] { + let len: Int32 = try buf.readInt() + var seq = [Int8]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterInt8.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordPushSubscriptionChanged: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypePushSubscriptionChanged: FfiConverterRustBuffer { typealias SwiftType = [PushSubscriptionChanged] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [PushSubscriptionChanged], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypePushSubscriptionChanged.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try PushSubscriptionChanged.read(from: buf) + static func read(from buf: Reader) throws -> [PushSubscriptionChanged] { + let len: Int32 = try buf.readInt() + var seq = [PushSubscriptionChanged]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypePushSubscriptionChanged.read(from: buf)) } + return seq } } diff --git a/swift-source/all/Generated/pushFFI.h b/swift-source/all/Generated/pushFFI.h index de3f544d..65069fbd 100644 --- a/swift-source/all/Generated/pushFFI.h +++ b/swift-source/all/Generated/pushFFI.h @@ -46,55 +46,55 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_push_f28b_PushManager_object_free( +void ffi_push_db7d_PushManager_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull push_f28b_PushManager_new( +void*_Nonnull push_db7d_PushManager_new( RustBuffer sender_id,RustBuffer server_host,RustBuffer http_protocol,RustBuffer bridge_type,RustBuffer registration_id,RustBuffer database_path, RustCallStatus *_Nonnull out_status ); -RustBuffer push_f28b_PushManager_subscribe( +RustBuffer push_db7d_PushManager_subscribe( void*_Nonnull ptr,RustBuffer channel_id,RustBuffer scope,RustBuffer app_server_sey, RustCallStatus *_Nonnull out_status ); -int8_t push_f28b_PushManager_unsubscribe( +int8_t push_db7d_PushManager_unsubscribe( void*_Nonnull ptr,RustBuffer channel_id, RustCallStatus *_Nonnull out_status ); -void push_f28b_PushManager_unsubscribe_all( +void push_db7d_PushManager_unsubscribe_all( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -int8_t push_f28b_PushManager_update( +int8_t push_db7d_PushManager_update( void*_Nonnull ptr,RustBuffer registration_token, RustCallStatus *_Nonnull out_status ); -RustBuffer push_f28b_PushManager_verify_connection( +RustBuffer push_db7d_PushManager_verify_connection( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer push_f28b_PushManager_decrypt( +RustBuffer push_db7d_PushManager_decrypt( void*_Nonnull ptr,RustBuffer channel_id,RustBuffer body,RustBuffer encoding,RustBuffer salt,RustBuffer dh, RustCallStatus *_Nonnull out_status ); -RustBuffer push_f28b_PushManager_dispatch_info_for_chid( +RustBuffer push_db7d_PushManager_dispatch_info_for_chid( void*_Nonnull ptr,RustBuffer channel_id, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_push_f28b_rustbuffer_alloc( +RustBuffer ffi_push_db7d_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_push_f28b_rustbuffer_from_bytes( +RustBuffer ffi_push_db7d_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_push_f28b_rustbuffer_free( +void ffi_push_db7d_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_push_f28b_rustbuffer_reserve( +RustBuffer ffi_push_db7d_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/swift-source/all/Generated/tabs.swift b/swift-source/all/Generated/tabs.swift new file mode 100644 index 00000000..bb3f023c --- /dev/null +++ b/swift-source/all/Generated/tabs.swift @@ -0,0 +1,806 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! +import Foundation + +// Depending on the consumer's build setup, the low-level FFI code +// might be in a separate module, or it might be compiled inline into +// this module. This is a bit of light hackery to work with both. +#if canImport(MozillaRustComponents) + import MozillaRustComponents +#endif + +private extension RustBuffer { + // Allocate a new buffer, copying the contents of a `UInt8` array. + init(bytes: [UInt8]) { + let rbuf = bytes.withUnsafeBufferPointer { ptr in + RustBuffer.from(ptr) + } + self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) + } + + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { + try! rustCall { ffi_tabs_1245_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + } + + // Frees the buffer in place. + // The buffer must not be used after this is called. + func deallocate() { + try! rustCall { ffi_tabs_1245_rustbuffer_free(self, $0) } + } +} + +private extension ForeignBytes { + init(bufferPointer: UnsafeBufferPointer) { + self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) + } +} + +// For every type used in the interface, we provide helper methods for conveniently +// lifting and lowering that type from C-compatible data, and for reading and writing +// values of that type in a buffer. + +// Helper classes/extensions that don't change. +// Someday, this will be in a libray of its own. + +private extension Data { + init(rustBuffer: RustBuffer) { + // TODO: This copies the buffer. Can we read directly from a + // Rust buffer? + self.init(bytes: rustBuffer.data!, count: Int(rustBuffer.len)) + } +} + +// A helper class to read values out of a byte buffer. +private class Reader { + let data: Data + var offset: Data.Index + + init(data: Data) { + self.data = data + offset = 0 + } + + // Reads an integer at the current offset, in big-endian order, and advances + // the offset on success. Throws if reading the integer would move the + // offset past the end of the buffer. + func readInt() throws -> T { + let range = offset ..< offset + MemoryLayout.size + guard data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + if T.self == UInt8.self { + let value = data[offset] + offset += 1 + return value as! T + } + var value: T = 0 + let _ = withUnsafeMutableBytes(of: &value) { data.copyBytes(to: $0, from: range) } + offset = range.upperBound + return value.bigEndian + } + + // Reads an arbitrary number of bytes, to be used to read + // raw bytes, this is useful when lifting strings + func readBytes(count: Int) throws -> [UInt8] { + let range = offset ..< (offset + count) + guard data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + var value = [UInt8](repeating: 0, count: count) + value.withUnsafeMutableBufferPointer { buffer in + data.copyBytes(to: buffer, from: range) + } + offset = range.upperBound + return value + } + + // Reads a float at the current offset. + @inlinable + func readFloat() throws -> Float { + return Float(bitPattern: try readInt()) + } + + // Reads a float at the current offset. + @inlinable + func readDouble() throws -> Double { + return Double(bitPattern: try readInt()) + } + + // Indicates if the offset has reached the end of the buffer. + @inlinable + func hasRemaining() -> Bool { + return offset < data.count + } +} + +// A helper class to write values into a byte buffer. +private class Writer { + var bytes: [UInt8] + var offset: Array.Index + + init() { + bytes = [] + offset = 0 + } + + func writeBytes(_ byteArr: S) where S: Sequence, S.Element == UInt8 { + bytes.append(contentsOf: byteArr) + } + + // Writes an integer in big-endian order. + // + // Warning: make sure what you are trying to write + // is in the correct type! + func writeInt(_ value: T) { + var value = value.bigEndian + withUnsafeBytes(of: &value) { bytes.append(contentsOf: $0) } + } + + @inlinable + func writeFloat(_ value: Float) { + writeInt(value.bitPattern) + } + + @inlinable + func writeDouble(_ value: Double) { + writeInt(value.bitPattern) + } +} + +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { + associatedtype FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) +} + +// Types conforming to `Primitive` pass themselves directly over the FFI. +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} + +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value + } + + static func lower(_ value: SwiftType) -> FfiType { + return value + } +} + +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} + +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { + let reader = Reader(data: Data(rustBuffer: buf)) + let value = try read(from: reader) + if reader.hasRemaining() { + throw UniffiInternalError.incompleteData + } + buf.deallocate() + return value + } + + static func lower(_ value: SwiftType) -> RustBuffer { + let writer = Writer() + write(value, into: writer) + return RustBuffer(bytes: writer.bytes) + } +} + +// An error type for FFI errors. These errors occur at the UniFFI level, not +// the library level. +private enum UniffiInternalError: LocalizedError { + case bufferOverflow + case incompleteData + case unexpectedOptionalTag + case unexpectedEnumCase + case unexpectedNullPointer + case unexpectedRustCallStatusCode + case unexpectedRustCallError + case unexpectedStaleHandle + case rustPanic(_ message: String) + + public var errorDescription: String? { + switch self { + case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" + case .incompleteData: return "The buffer still has data after lifting its containing value" + case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" + case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" + case .unexpectedNullPointer: return "Raw pointer value was null" + case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" + case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" + case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" + case let .rustPanic(message): return message + } + } +} + +private let CALL_SUCCESS: Int8 = 0 +private let CALL_ERROR: Int8 = 1 +private let CALL_PANIC: Int8 = 2 + +private extension RustCallStatus { + init() { + self.init( + code: CALL_SUCCESS, + errorBuf: RustBuffer( + capacity: 0, + len: 0, + data: nil + ) + ) + } +} + +private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { + try makeRustCall(callback, errorHandler: { + $0.deallocate() + return UniffiInternalError.unexpectedRustCallError + }) +} + +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) +} + +private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { + var callStatus = RustCallStatus() + let returnedVal = callback(&callStatus) + switch callStatus.code { + case CALL_SUCCESS: + return returnedVal + + case CALL_ERROR: + throw try errorHandler(callStatus.errorBuf) + + case CALL_PANIC: + // When the rust code sees a panic, it tries to construct a RustBuffer + // with the message. But if that code panics, then it just sends back + // an empty buffer. + if callStatus.errorBuf.len > 0 { + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.rustPanic("Rust panic") + } + + default: + throw UniffiInternalError.unexpectedRustCallStatusCode + } +} + +// Public interface members begin here. + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum TabsDeviceType { + case desktop + case mobile + case tablet + case vr + case tv + case unknown +} + +private struct FfiConverterTypeTabsDeviceType: FfiConverterRustBuffer { + typealias SwiftType = TabsDeviceType + + static func read(from buf: Reader) throws -> TabsDeviceType { + let variant: Int32 = try buf.readInt() + switch variant { + case 1: return .desktop + + case 2: return .mobile + + case 3: return .tablet + + case 4: return .vr + + case 5: return .tv + + case 6: return .unknown + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + static func write(_ value: TabsDeviceType, into buf: Writer) { + switch value { + case .desktop: + buf.writeInt(Int32(1)) + + case .mobile: + buf.writeInt(Int32(2)) + + case .tablet: + buf.writeInt(Int32(3)) + + case .vr: + buf.writeInt(Int32(4)) + + case .tv: + buf.writeInt(Int32(5)) + + case .unknown: + buf.writeInt(Int32(6)) + } + } +} + +extension TabsDeviceType: Equatable, Hashable {} + +public protocol TabsStoreProtocol { + func getAll() -> [ClientRemoteTabs] + func setLocalTabs(remoteTabs: [RemoteTabRecord]) + func registerWithSyncManager() + func reset() throws + func sync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String, localId: String) throws -> String +} + +public class TabsStore: TabsStoreProtocol { + fileprivate let pointer: UnsafeMutableRawPointer + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + public convenience init(path: String) { + self.init(unsafeFromRawPointer: try! + + rustCall { + tabs_1245_TabsStore_new( + FfiConverterString.lower(path), $0 + ) + }) + } + + deinit { + try! rustCall { ffi_tabs_1245_TabsStore_object_free(pointer, $0) } + } + + public func getAll() -> [ClientRemoteTabs] { + return try! FfiConverterSequenceTypeClientRemoteTabs.lift( + try! + rustCall { + tabs_1245_TabsStore_get_all(self.pointer, $0) + } + ) + } + + public func setLocalTabs(remoteTabs: [RemoteTabRecord]) { + try! + rustCall { + tabs_1245_TabsStore_set_local_tabs(self.pointer, + FfiConverterSequenceTypeRemoteTabRecord.lower(remoteTabs), $0) + } + } + + public func registerWithSyncManager() { + try! + rustCall { + tabs_1245_TabsStore_register_with_sync_manager(self.pointer, $0) + } + } + + public func reset() throws { + try + rustCallWithError(FfiConverterTypeTabsError.self) { + tabs_1245_TabsStore_reset(self.pointer, $0) + } + } + + public func sync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String, localId: String) throws -> String { + return try FfiConverterString.lift( + try + rustCallWithError(FfiConverterTypeTabsError.self) { + tabs_1245_TabsStore_sync(self.pointer, + FfiConverterString.lower(keyId), + FfiConverterString.lower(accessToken), + FfiConverterString.lower(syncKey), + FfiConverterString.lower(tokenserverUrl), + FfiConverterString.lower(localId), $0) + } + ) + } +} + +private struct FfiConverterTypeTabsStore: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = TabsStore + + static func read(from buf: Reader) throws -> TabsStore { + let v: UInt64 = try buf.readInt() + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if ptr == nil { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + static func write(_ value: TabsStore, into buf: Writer) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } + + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> TabsStore { + return TabsStore(unsafeFromRawPointer: pointer) + } + + static func lower(_ value: TabsStore) -> UnsafeMutableRawPointer { + return value.pointer + } +} + +public struct RemoteTabRecord { + public var title: String + public var urlHistory: [String] + public var icon: String? + public var lastUsed: Int64 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(title: String, urlHistory: [String], icon: String?, lastUsed: Int64) { + self.title = title + self.urlHistory = urlHistory + self.icon = icon + self.lastUsed = lastUsed + } +} + +extension RemoteTabRecord: Equatable, Hashable { + public static func == (lhs: RemoteTabRecord, rhs: RemoteTabRecord) -> Bool { + if lhs.title != rhs.title { + return false + } + if lhs.urlHistory != rhs.urlHistory { + return false + } + if lhs.icon != rhs.icon { + return false + } + if lhs.lastUsed != rhs.lastUsed { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(title) + hasher.combine(urlHistory) + hasher.combine(icon) + hasher.combine(lastUsed) + } +} + +private struct FfiConverterTypeRemoteTabRecord: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> RemoteTabRecord { + return try RemoteTabRecord( + title: FfiConverterString.read(from: buf), + urlHistory: FfiConverterSequenceString.read(from: buf), + icon: FfiConverterOptionString.read(from: buf), + lastUsed: FfiConverterInt64.read(from: buf) + ) + } + + fileprivate static func write(_ value: RemoteTabRecord, into buf: Writer) { + FfiConverterString.write(value.title, into: buf) + FfiConverterSequenceString.write(value.urlHistory, into: buf) + FfiConverterOptionString.write(value.icon, into: buf) + FfiConverterInt64.write(value.lastUsed, into: buf) + } +} + +public struct ClientRemoteTabs { + public var clientId: String + public var clientName: String + public var deviceType: TabsDeviceType + public var remoteTabs: [RemoteTabRecord] + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(clientId: String, clientName: String, deviceType: TabsDeviceType, remoteTabs: [RemoteTabRecord]) { + self.clientId = clientId + self.clientName = clientName + self.deviceType = deviceType + self.remoteTabs = remoteTabs + } +} + +extension ClientRemoteTabs: Equatable, Hashable { + public static func == (lhs: ClientRemoteTabs, rhs: ClientRemoteTabs) -> Bool { + if lhs.clientId != rhs.clientId { + return false + } + if lhs.clientName != rhs.clientName { + return false + } + if lhs.deviceType != rhs.deviceType { + return false + } + if lhs.remoteTabs != rhs.remoteTabs { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(clientId) + hasher.combine(clientName) + hasher.combine(deviceType) + hasher.combine(remoteTabs) + } +} + +private struct FfiConverterTypeClientRemoteTabs: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> ClientRemoteTabs { + return try ClientRemoteTabs( + clientId: FfiConverterString.read(from: buf), + clientName: FfiConverterString.read(from: buf), + deviceType: FfiConverterTypeTabsDeviceType.read(from: buf), + remoteTabs: FfiConverterSequenceTypeRemoteTabRecord.read(from: buf) + ) + } + + fileprivate static func write(_ value: ClientRemoteTabs, into buf: Writer) { + FfiConverterString.write(value.clientId, into: buf) + FfiConverterString.write(value.clientName, into: buf) + FfiConverterTypeTabsDeviceType.write(value.deviceType, into: buf) + FfiConverterSequenceTypeRemoteTabRecord.write(value.remoteTabs, into: buf) + } +} + +public enum TabsError { + // Simple error enums only carry a message + case SyncAdapterError(message: String) + + // Simple error enums only carry a message + case SyncResetError(message: String) + + // Simple error enums only carry a message + case JsonError(message: String) + + // Simple error enums only carry a message + case UrlParseError(message: String) + + // Simple error enums only carry a message + case SqlError(message: String) + + // Simple error enums only carry a message + case OpenDatabaseError(message: String) +} + +private struct FfiConverterTypeTabsError: FfiConverterRustBuffer { + typealias SwiftType = TabsError + + static func read(from buf: Reader) throws -> TabsError { + let variant: Int32 = try buf.readInt() + switch variant { + case 1: return .SyncAdapterError( + message: try FfiConverterString.read(from: buf) + ) + + case 2: return .SyncResetError( + message: try FfiConverterString.read(from: buf) + ) + + case 3: return .JsonError( + message: try FfiConverterString.read(from: buf) + ) + + case 4: return .UrlParseError( + message: try FfiConverterString.read(from: buf) + ) + + case 5: return .SqlError( + message: try FfiConverterString.read(from: buf) + ) + + case 6: return .OpenDatabaseError( + message: try FfiConverterString.read(from: buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + static func write(_ value: TabsError, into buf: Writer) { + switch value { + case let .SyncAdapterError(message): + buf.writeInt(Int32(1)) + FfiConverterString.write(message, into: buf) + case let .SyncResetError(message): + buf.writeInt(Int32(2)) + FfiConverterString.write(message, into: buf) + case let .JsonError(message): + buf.writeInt(Int32(3)) + FfiConverterString.write(message, into: buf) + case let .UrlParseError(message): + buf.writeInt(Int32(4)) + FfiConverterString.write(message, into: buf) + case let .SqlError(message): + buf.writeInt(Int32(5)) + FfiConverterString.write(message, into: buf) + case let .OpenDatabaseError(message): + buf.writeInt(Int32(6)) + FfiConverterString.write(message, into: buf) + } + } +} + +extension TabsError: Equatable, Hashable {} + +extension TabsError: Error {} +private struct FfiConverterInt64: FfiConverterPrimitive { + typealias FfiType = Int64 + typealias SwiftType = Int64 + + static func read(from buf: Reader) throws -> Int64 { + return try lift(buf.readInt()) + } + + static func write(_ value: Int64, into buf: Writer) { + buf.writeInt(lower(value)) + } +} + +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer + + static func lift(_ value: RustBuffer) throws -> String { + defer { + value.deallocate() + } + if value.data == nil { + return String() + } + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) + return String(bytes: bytes, encoding: String.Encoding.utf8)! + } + + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in + // The swift string gives us int8_t, we want uint8_t. + ptr.withMemoryRebound(to: UInt8.self) { ptr in + // The swift string gives us a trailing null byte, we don't want it. + let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) + return RustBuffer.from(buf) + } + } + } + + static func read(from buf: Reader) throws -> String { + let len: Int32 = try buf.readInt() + return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! + } + + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) + buf.writeInt(len) + buf.writeBytes(value.utf8) + } +} + +// Helper code for TabsStore class is found in ObjectTemplate.swift +// Helper code for ClientRemoteTabs record is found in RecordTemplate.swift +// Helper code for RemoteTabRecord record is found in RecordTemplate.swift +// Helper code for TabsDeviceType enum is found in EnumTemplate.swift +// Helper code for TabsError error is found in ErrorTemplate.swift + +private struct FfiConverterOptionString: FfiConverterRustBuffer { + typealias SwiftType = String? + + static func write(_ value: SwiftType, into buf: Writer) { + guard let value = value else { + buf.writeInt(Int8(0)) + return + } + buf.writeInt(Int8(1)) + FfiConverterString.write(value, into: buf) + } + + static func read(from buf: Reader) throws -> SwiftType { + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +private struct FfiConverterSequenceString: FfiConverterRustBuffer { + typealias SwiftType = [String] + + static func write(_ value: [String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterString.write(item, into: buf) + } + } + + static func read(from buf: Reader) throws -> [String] { + let len: Int32 = try buf.readInt() + var seq = [String]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterString.read(from: buf)) + } + return seq + } +} + +private struct FfiConverterSequenceTypeClientRemoteTabs: FfiConverterRustBuffer { + typealias SwiftType = [ClientRemoteTabs] + + static func write(_ value: [ClientRemoteTabs], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeClientRemoteTabs.write(item, into: buf) + } + } + + static func read(from buf: Reader) throws -> [ClientRemoteTabs] { + let len: Int32 = try buf.readInt() + var seq = [ClientRemoteTabs]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeClientRemoteTabs.read(from: buf)) + } + return seq + } +} + +private struct FfiConverterSequenceTypeRemoteTabRecord: FfiConverterRustBuffer { + typealias SwiftType = [RemoteTabRecord] + + static func write(_ value: [RemoteTabRecord], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeRemoteTabRecord.write(item, into: buf) + } + } + + static func read(from buf: Reader) throws -> [RemoteTabRecord] { + let len: Int32 = try buf.readInt() + var seq = [RemoteTabRecord]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeRemoteTabRecord.read(from: buf)) + } + return seq + } +} + +/** + * Top level initializers and tear down methods. + * + * This is generated by uniffi. + */ +public enum TabsLifecycle { + /** + * Initialize the FFI and Rust library. This should be only called once per application. + */ + func initialize() { + // No initialization code needed + } +} diff --git a/swift-source/all/Generated/tabsFFI.h b/swift-source/all/Generated/tabsFFI.h new file mode 100644 index 00000000..481639c1 --- /dev/null +++ b/swift-source/all/Generated/tabsFFI.h @@ -0,0 +1,92 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +#pragma once + +#include +#include + +// The following structs are used to implement the lowest level +// of the FFI, and thus useful to multiple uniffied crates. +// We ensure they are declared exactly once, with a header guard, UNIFFI_SHARED_H. +#ifdef UNIFFI_SHARED_H + // We also try to prevent mixing versions of shared uniffi header structs. + // If you add anything to the #else block, you must increment the version suffix in UNIFFI_SHARED_HEADER_V4 + #ifndef UNIFFI_SHARED_HEADER_V4 + #error Combining helper code from multiple versions of uniffi is not supported + #endif // ndef UNIFFI_SHARED_HEADER_V4 +#else +#define UNIFFI_SHARED_H +#define UNIFFI_SHARED_HEADER_V4 +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ + +typedef struct RustBuffer +{ + int32_t capacity; + int32_t len; + uint8_t *_Nullable data; +} RustBuffer; + +typedef int32_t (*ForeignCallback)(uint64_t, int32_t, RustBuffer, RustBuffer *_Nonnull); + +typedef struct ForeignBytes +{ + int32_t len; + const uint8_t *_Nullable data; +} ForeignBytes; + +// Error definitions +typedef struct RustCallStatus { + int8_t code; + RustBuffer errorBuf; +} RustCallStatus; + +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ +#endif // def UNIFFI_SHARED_H + +void ffi_tabs_1245_TabsStore_object_free( + void*_Nonnull ptr, + RustCallStatus *_Nonnull out_status + ); +void*_Nonnull tabs_1245_TabsStore_new( + RustBuffer path, + RustCallStatus *_Nonnull out_status + ); +RustBuffer tabs_1245_TabsStore_get_all( + void*_Nonnull ptr, + RustCallStatus *_Nonnull out_status + ); +void tabs_1245_TabsStore_set_local_tabs( + void*_Nonnull ptr,RustBuffer remote_tabs, + RustCallStatus *_Nonnull out_status + ); +void tabs_1245_TabsStore_register_with_sync_manager( + void*_Nonnull ptr, + RustCallStatus *_Nonnull out_status + ); +void tabs_1245_TabsStore_reset( + void*_Nonnull ptr, + RustCallStatus *_Nonnull out_status + ); +RustBuffer tabs_1245_TabsStore_sync( + void*_Nonnull ptr,RustBuffer key_id,RustBuffer access_token,RustBuffer sync_key,RustBuffer tokenserver_url,RustBuffer local_id, + RustCallStatus *_Nonnull out_status + ); +RustBuffer ffi_tabs_1245_rustbuffer_alloc( + int32_t size, + RustCallStatus *_Nonnull out_status + ); +RustBuffer ffi_tabs_1245_rustbuffer_from_bytes( + ForeignBytes bytes, + RustCallStatus *_Nonnull out_status + ); +void ffi_tabs_1245_rustbuffer_free( + RustBuffer buf, + RustCallStatus *_Nonnull out_status + ); +RustBuffer ffi_tabs_1245_rustbuffer_reserve( + RustBuffer buf,int32_t additional, + RustCallStatus *_Nonnull out_status + ); diff --git a/swift-source/all/Places/Places.swift b/swift-source/all/Places/Places.swift index 625a236f..e1fd427b 100644 --- a/swift-source/all/Places/Places.swift +++ b/swift-source/all/Places/Places.swift @@ -7,8 +7,6 @@ import os.log internal typealias UniffiPlacesApi = PlacesApi internal typealias UniffiPlacesConnection = PlacesConnection -public typealias Url = String -public typealias Guid = String /** * This is specifically for throwing when there is diff --git a/swift-source/all/SyncUnlockInfo.swift b/swift-source/all/SyncUnlockInfo.swift index 26f86a0a..aa80947e 100644 --- a/swift-source/all/SyncUnlockInfo.swift +++ b/swift-source/all/SyncUnlockInfo.swift @@ -12,12 +12,14 @@ open class SyncUnlockInfo { public var syncKey: String public var tokenserverURL: String public var loginEncryptionKey: String + public var tabsLocalId: String - public init(kid: String, fxaAccessToken: String, syncKey: String, tokenserverURL: String, loginEncryptionKey: String) { + public init(kid: String, fxaAccessToken: String, syncKey: String, tokenserverURL: String, loginEncryptionKey: String, tabsLocalId: String) { self.kid = kid self.fxaAccessToken = fxaAccessToken self.syncKey = syncKey self.tokenserverURL = tokenserverURL self.loginEncryptionKey = loginEncryptionKey + self.tabsLocalId = tabsLocalId } } diff --git a/swift-source/all/Tabs/Tabs.swift b/swift-source/all/Tabs/Tabs.swift new file mode 100644 index 00000000..f4401c09 --- /dev/null +++ b/swift-source/all/Tabs/Tabs.swift @@ -0,0 +1,47 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import Foundation + +open class TabsStorage { + private var store: TabsStore + private let queue = DispatchQueue(label: "com.mozilla.tabs-storage") + + public init(databasePath: String) { + store = TabsStore(path: databasePath) + } + + /// Get all tabs by client. + open func getAll() -> [ClientRemoteTabs] { + return queue.sync { + return self.store.getAll() + } + } + + /// Set the local tabs. + open func setLocalTabs(remoteTabs: [RemoteTabRecord]) { + queue.sync { + self.store.setLocalTabs(remoteTabs: remoteTabs) + } + } + + open func reset() throws { + try queue.sync { + try self.store.reset() + } + } + + open func sync(unlockInfo: SyncUnlockInfo) throws -> String { + return try queue.sync { + return try self.store + .sync( + keyId: unlockInfo.kid, + accessToken: unlockInfo.fxaAccessToken, + syncKey: unlockInfo.syncKey, + tokenserverUrl: unlockInfo.tokenserverURL, + localId: unlockInfo.tabsLocalId + ) + } + } +} diff --git a/swift-source/all/crashtest.swift b/swift-source/all/crashtest.swift index 0dd35682..c121198d 100644 --- a/swift-source/all/crashtest.swift +++ b/swift-source/all/crashtest.swift @@ -19,13 +19,13 @@ private extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_crashtest_5d0e_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_crashtest_9d89_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_crashtest_5d0e_rustbuffer_free(self, $0) } + try! rustCall { ffi_crashtest_9d89_rustbuffer_free(self, $0) } } } @@ -147,45 +147,39 @@ private class Writer { } } -// Types conforming to `Serializable` can be read and written in a bytebuffer. -private protocol Serializable { - func write(into: Writer) - static func read(from: Reader) throws -> Self -} - -// Types confirming to `ViaFfi` can be transferred back-and-for over the FFI. -// This is analogous to the Rust trait of the same name. -private protocol ViaFfi: Serializable { +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { associatedtype FfiType - static func lift(_ v: FfiType) throws -> Self - func lower() -> FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol Primitive {} - -private extension Primitive { - typealias FfiType = Self +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} - static func lift(_ v: Self) throws -> Self { - return v +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value } - func lower() -> Self { - return self + static func lower(_ value: SwiftType) -> FfiType { + return value } } -// Types conforming to `ViaFfiUsingByteBuffer` lift and lower into a bytebuffer. -// Use this for complex types where it's hard to write a custom lift/lower. -private protocol ViaFfiUsingByteBuffer: Serializable {} - -private extension ViaFfiUsingByteBuffer { - typealias FfiType = RustBuffer +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - static func lift(_ buf: FfiType) throws -> Self { +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) + let value = try read(from: reader) if reader.hasRemaining() { throw UniffiInternalError.incompleteData } @@ -193,9 +187,9 @@ private extension ViaFfiUsingByteBuffer { return value } - func lower() -> FfiType { + static func lower(_ value: SwiftType) -> RustBuffer { let writer = Writer() - write(into: writer) + write(value, into: writer) return RustBuffer(bytes: writer.bytes) } } @@ -252,8 +246,11 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T }) } -private func rustCallWithError(_: E.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: { try E.lift($0) }) +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { @@ -271,7 +268,7 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) // with the message. But if that code panics, then it just sends back // an empty buffer. if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try String.lift(callStatus.errorBuf)) + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) } else { callStatus.errorBuf.deallocate() throw UniffiInternalError.rustPanic("Rust panic") @@ -282,110 +279,13 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -// Protocols for converters we'll implement in templates - -private protocol FfiConverter { - associatedtype SwiftType - associatedtype FfiType - - static func lift(_ ffiValue: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - - static func read(from: Reader) throws -> SwiftType - static func write(_ value: SwiftType, into: Writer) -} - -private protocol FfiConverterUsingByteBuffer: FfiConverter where FfiType == RustBuffer { - // Empty, because we want to declare some helper methods in the extension below. -} - -extension FfiConverterUsingByteBuffer { - static func lower(_ value: SwiftType) -> FfiType { - let writer = Writer() - Self.write(value, into: writer) - return RustBuffer(bytes: writer.bytes) - } - - static func lift(_ buf: FfiType) throws -> SwiftType { - let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) - if reader.hasRemaining() { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } -} - -// Helpers for structural types. Note that because of canonical_names, it /should/ be impossible -// to make another `FfiConverterSequence` etc just using the UDL. -private enum FfiConverterSequence { - static func write(_ value: [T], into buf: Writer, writeItem: (T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for item in value { - writeItem(item, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> [T] { - let len: Int32 = try buf.readInt() - var seq = [T]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try readItem(buf)) - } - return seq - } -} - -private enum FfiConverterOptional { - static func write(_ value: T?, into buf: Writer, writeItem: (T, Writer) -> Void) { - guard let value = value else { - buf.writeInt(Int8(0)) - return - } - buf.writeInt(Int8(1)) - writeItem(value, buf) - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> T? { - switch try buf.readInt() as Int8 { - case 0: return nil - case 1: return try readItem(buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -private enum FfiConverterDictionary { - static func write(_ value: [String: T], into buf: Writer, writeItem: (String, T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for (key, value) in value { - writeItem(key, value, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> (String, T)) throws -> [String: T] { - let len: Int32 = try buf.readInt() - var dict = [String: T]() - dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { - let (key, value) = try readItem(buf) - dict[key] = value - } - return dict - } -} - // Public interface members begin here. public func triggerRustAbort() { try! rustCall { - crashtest_5d0e_trigger_rust_abort($0) + crashtest_9d89_trigger_rust_abort($0) } } @@ -393,15 +293,15 @@ public func triggerRustPanic() { try! rustCall { - crashtest_5d0e_trigger_rust_panic($0) + crashtest_9d89_trigger_rust_panic($0) } } public func triggerRustError() throws { try - rustCallWithError(CrashTestError.self) { - crashtest_5d0e_trigger_rust_error($0) + rustCallWithError(FfiConverterTypeCrashTestError.self) { + crashtest_9d89_trigger_rust_error($0) } } @@ -410,23 +310,25 @@ public enum CrashTestError { case ErrorFromTheRustCode(message: String) } -extension CrashTestError: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> CrashTestError { +private struct FfiConverterTypeCrashTestError: FfiConverterRustBuffer { + typealias SwiftType = CrashTestError + + static func read(from buf: Reader) throws -> CrashTestError { let variant: Int32 = try buf.readInt() switch variant { case 1: return .ErrorFromTheRustCode( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: CrashTestError, into buf: Writer) { + switch value { case let .ErrorFromTheRustCode(message): buf.writeInt(Int32(1)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) } } } @@ -434,22 +336,23 @@ extension CrashTestError: ViaFfiUsingByteBuffer, ViaFfi { extension CrashTestError: Equatable, Hashable {} extension CrashTestError: Error {} -extension String: ViaFfi { - fileprivate typealias FfiType = RustBuffer +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer - fileprivate static func lift(_ v: FfiType) throws -> Self { + static func lift(_ value: RustBuffer) throws -> String { defer { - v.deallocate() + value.deallocate() } - if v.data == nil { + if value.data == nil { return String() } - let bytes = UnsafeBufferPointer(start: v.data!, count: Int(v.len)) + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) return String(bytes: bytes, encoding: String.Encoding.utf8)! } - fileprivate func lower() -> FfiType { - return utf8CString.withUnsafeBufferPointer { ptr in + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in // The swift string gives us int8_t, we want uint8_t. ptr.withMemoryRebound(to: UInt8.self) { ptr in // The swift string gives us a trailing null byte, we don't want it. @@ -459,15 +362,15 @@ extension String: ViaFfi { } } - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> String { let len: Int32 = try buf.readInt() return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! } - fileprivate func write(into buf: Writer) { - let len = Int32(utf8.count) + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) buf.writeInt(len) - buf.writeBytes(utf8) + buf.writeBytes(value.utf8) } } diff --git a/swift-source/all/crashtestFFI.h b/swift-source/all/crashtestFFI.h index c87da5d8..30df3211 100644 --- a/swift-source/all/crashtestFFI.h +++ b/swift-source/all/crashtestFFI.h @@ -46,31 +46,31 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void crashtest_5d0e_trigger_rust_abort( +void crashtest_9d89_trigger_rust_abort( RustCallStatus *_Nonnull out_status ); -void crashtest_5d0e_trigger_rust_panic( +void crashtest_9d89_trigger_rust_panic( RustCallStatus *_Nonnull out_status ); -void crashtest_5d0e_trigger_rust_error( +void crashtest_9d89_trigger_rust_error( RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_crashtest_5d0e_rustbuffer_alloc( +RustBuffer ffi_crashtest_9d89_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_crashtest_5d0e_rustbuffer_from_bytes( +RustBuffer ffi_crashtest_9d89_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_crashtest_5d0e_rustbuffer_free( +void ffi_crashtest_9d89_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_crashtest_5d0e_rustbuffer_reserve( +RustBuffer ffi_crashtest_9d89_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/swift-source/focus/Generated/Metrics/Metrics.swift b/swift-source/focus/Generated/Metrics/Metrics.swift index ad9b9c99..f06bba19 100644 --- a/swift-source/focus/Generated/Metrics/Metrics.swift +++ b/swift-source/focus/Generated/Metrics/Metrics.swift @@ -22,7 +22,7 @@ extension GleanMetrics { // Intentionally left private, no external user can instantiate a new global object. } - public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 5, day: 12, hour: 3, minute: 18, second: 19)) + public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 5, day: 26, hour: 15, minute: 12, second: 40)) } enum NimbusEvents { diff --git a/swift-source/focus/Generated/nimbus.swift b/swift-source/focus/Generated/nimbus.swift index 07341853..c12a5603 100644 --- a/swift-source/focus/Generated/nimbus.swift +++ b/swift-source/focus/Generated/nimbus.swift @@ -19,13 +19,13 @@ private extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_nimbus_302d_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_nimbus_e97_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_nimbus_302d_rustbuffer_free(self, $0) } + try! rustCall { ffi_nimbus_e97_rustbuffer_free(self, $0) } } } @@ -147,45 +147,39 @@ private class Writer { } } -// Types conforming to `Serializable` can be read and written in a bytebuffer. -private protocol Serializable { - func write(into: Writer) - static func read(from: Reader) throws -> Self -} - -// Types confirming to `ViaFfi` can be transferred back-and-for over the FFI. -// This is analogous to the Rust trait of the same name. -private protocol ViaFfi: Serializable { +// Protocol for types that transfer other types across the FFI. This is +// analogous go the Rust trait of the same name. +private protocol FfiConverter { associatedtype FfiType - static func lift(_ v: FfiType) throws -> Self - func lower() -> FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: Reader) throws -> SwiftType + static func write(_ value: SwiftType, into buf: Writer) } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol Primitive {} +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} -private extension Primitive { - typealias FfiType = Self - - static func lift(_ v: Self) throws -> Self { - return v +extension FfiConverterPrimitive { + static func lift(_ value: FfiType) throws -> SwiftType { + return value } - func lower() -> Self { - return self + static func lower(_ value: SwiftType) -> FfiType { + return value } } -// Types conforming to `ViaFfiUsingByteBuffer` lift and lower into a bytebuffer. -// Use this for complex types where it's hard to write a custom lift/lower. -private protocol ViaFfiUsingByteBuffer: Serializable {} - -private extension ViaFfiUsingByteBuffer { - typealias FfiType = RustBuffer +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - static func lift(_ buf: FfiType) throws -> Self { +extension FfiConverterRustBuffer { + static func lift(_ buf: RustBuffer) throws -> SwiftType { let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) + let value = try read(from: reader) if reader.hasRemaining() { throw UniffiInternalError.incompleteData } @@ -193,9 +187,9 @@ private extension ViaFfiUsingByteBuffer { return value } - func lower() -> FfiType { + static func lower(_ value: SwiftType) -> RustBuffer { let writer = Writer() - write(into: writer) + write(value, into: writer) return RustBuffer(bytes: writer.bytes) } } @@ -252,8 +246,11 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T }) } -private func rustCallWithError(_: E.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: { try E.lift($0) }) +private func rustCallWithError +(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T + where F.SwiftType: Error, F.FfiType == RustBuffer +{ + try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { @@ -271,7 +268,7 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) // with the message. But if that code panics, then it just sends back // an empty buffer. if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try String.lift(callStatus.errorBuf)) + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) } else { callStatus.errorBuf.deallocate() throw UniffiInternalError.rustPanic("Rust panic") @@ -282,103 +279,6 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -// Protocols for converters we'll implement in templates - -private protocol FfiConverter { - associatedtype SwiftType - associatedtype FfiType - - static func lift(_ ffiValue: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - - static func read(from: Reader) throws -> SwiftType - static func write(_ value: SwiftType, into: Writer) -} - -private protocol FfiConverterUsingByteBuffer: FfiConverter where FfiType == RustBuffer { - // Empty, because we want to declare some helper methods in the extension below. -} - -extension FfiConverterUsingByteBuffer { - static func lower(_ value: SwiftType) -> FfiType { - let writer = Writer() - Self.write(value, into: writer) - return RustBuffer(bytes: writer.bytes) - } - - static func lift(_ buf: FfiType) throws -> SwiftType { - let reader = Reader(data: Data(rustBuffer: buf)) - let value = try Self.read(from: reader) - if reader.hasRemaining() { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } -} - -// Helpers for structural types. Note that because of canonical_names, it /should/ be impossible -// to make another `FfiConverterSequence` etc just using the UDL. -private enum FfiConverterSequence { - static func write(_ value: [T], into buf: Writer, writeItem: (T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for item in value { - writeItem(item, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> [T] { - let len: Int32 = try buf.readInt() - var seq = [T]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try readItem(buf)) - } - return seq - } -} - -private enum FfiConverterOptional { - static func write(_ value: T?, into buf: Writer, writeItem: (T, Writer) -> Void) { - guard let value = value else { - buf.writeInt(Int8(0)) - return - } - buf.writeInt(Int8(1)) - writeItem(value, buf) - } - - static func read(from buf: Reader, readItem: (Reader) throws -> T) throws -> T? { - switch try buf.readInt() as Int8 { - case 0: return nil - case 1: return try readItem(buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -private enum FfiConverterDictionary { - static func write(_ value: [String: T], into buf: Writer, writeItem: (String, T, Writer) -> Void) { - let len = Int32(value.count) - buf.writeInt(len) - for (key, value) in value { - writeItem(key, value, buf) - } - } - - static func read(from buf: Reader, readItem: (Reader) throws -> (String, T)) throws -> [String: T] { - let len: Int32 = try buf.readInt() - var dict = [String: T]() - dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { - let (key, value) = try readItem(buf) - dict[key] = value - } - return dict - } -} - // Public interface members begin here. // Note that we don't yet support `indirect` for enums. @@ -390,19 +290,24 @@ public enum EnrollmentChangeEventType { case unenrollment } -extension EnrollmentChangeEventType: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> EnrollmentChangeEventType { +private struct FfiConverterTypeEnrollmentChangeEventType: FfiConverterRustBuffer { + typealias SwiftType = EnrollmentChangeEventType + + static func read(from buf: Reader) throws -> EnrollmentChangeEventType { let variant: Int32 = try buf.readInt() switch variant { case 1: return .enrollment + case 2: return .disqualification + case 3: return .unenrollment + default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: EnrollmentChangeEventType, into buf: Writer) { + switch value { case .enrollment: buf.writeInt(Int32(1)) @@ -433,15 +338,15 @@ public protocol NimbusClientProtocol { func optInWithBranch(experimentSlug: String, branch: String) throws -> [EnrollmentChangeEvent] func optOut(experimentSlug: String) throws -> [EnrollmentChangeEvent] func resetTelemetryIdentifiers(newRandomizationUnits: AvailableRandomizationUnits) throws -> [EnrollmentChangeEvent] - func createTargetingHelper(additionalContext: String?) throws -> NimbusTargetingHelper - func createStringHelper(additionalContext: String?) throws -> NimbusStringHelper + func createTargetingHelper(additionalContext: JsonObject?) throws -> NimbusTargetingHelper + func createStringHelper(additionalContext: JsonObject?) throws -> NimbusStringHelper } public class NimbusClient: NimbusClientProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer @@ -450,153 +355,184 @@ public class NimbusClient: NimbusClientProtocol { public convenience init(appCtx: AppContext, dbpath: String, remoteSettingsConfig: RemoteSettingsConfig?, availableRandomizationUnits: AvailableRandomizationUnits) throws { self.init(unsafeFromRawPointer: try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_new(appCtx.lower(), dbpath.lower(), FfiConverterOptionRecordRemoteSettingsConfig.lower(remoteSettingsConfig), availableRandomizationUnits.lower(), $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_new( + FfiConverterTypeAppContext.lower(appCtx), + FfiConverterString.lower(dbpath), + FfiConverterOptionTypeRemoteSettingsConfig.lower(remoteSettingsConfig), + FfiConverterTypeAvailableRandomizationUnits.lower(availableRandomizationUnits), $0 + ) }) } deinit { - try! rustCall { ffi_nimbus_302d_NimbusClient_object_free(pointer, $0) } + try! rustCall { ffi_nimbus_e97_NimbusClient_object_free(pointer, $0) } } public func initialize() throws { try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_initialize(self.pointer, $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_initialize(self.pointer, $0) } } public func getExperimentBranch(id: String) throws -> String? { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_experiment_branch(self.pointer, id.lower(), $0) - } - return try FfiConverterOptionString.lift(_retval) + return try FfiConverterOptionString.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_experiment_branch(self.pointer, + FfiConverterString.lower(id), $0) + } + ) } public func getFeatureConfigVariables(featureId: String) throws -> String? { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_feature_config_variables(self.pointer, featureId.lower(), $0) - } - return try FfiConverterOptionString.lift(_retval) + return try FfiConverterOptionString.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_feature_config_variables(self.pointer, + FfiConverterString.lower(featureId), $0) + } + ) } public func getExperimentBranches(experimentSlug: String) throws -> [ExperimentBranch] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_experiment_branches(self.pointer, experimentSlug.lower(), $0) - } - return try FfiConverterSequenceRecordExperimentBranch.lift(_retval) + return try FfiConverterSequenceTypeExperimentBranch.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_experiment_branches(self.pointer, + FfiConverterString.lower(experimentSlug), $0) + } + ) } public func getActiveExperiments() throws -> [EnrolledExperiment] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_active_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordEnrolledExperiment.lift(_retval) + return try FfiConverterSequenceTypeEnrolledExperiment.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_active_experiments(self.pointer, $0) + } + ) } public func getAvailableExperiments() throws -> [AvailableExperiment] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_available_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordAvailableExperiment.lift(_retval) + return try FfiConverterSequenceTypeAvailableExperiment.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_available_experiments(self.pointer, $0) + } + ) } public func getGlobalUserParticipation() throws -> Bool { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_get_global_user_participation(self.pointer, $0) - } - return try Bool.lift(_retval) + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_get_global_user_participation(self.pointer, $0) + } + ) } public func setGlobalUserParticipation(optIn: Bool) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_set_global_user_participation(self.pointer, optIn.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_set_global_user_participation(self.pointer, + FfiConverterBool.lower(optIn), $0) + } + ) } public func updateExperiments() throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_update_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_update_experiments(self.pointer, $0) + } + ) } public func fetchExperiments() throws { try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_fetch_experiments(self.pointer, $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_fetch_experiments(self.pointer, $0) } } public func applyPendingExperiments() throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_apply_pending_experiments(self.pointer, $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_apply_pending_experiments(self.pointer, $0) + } + ) } public func setExperimentsLocally(experimentsJson: String) throws { try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_set_experiments_locally(self.pointer, experimentsJson.lower(), $0) + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_set_experiments_locally(self.pointer, + FfiConverterString.lower(experimentsJson), $0) } } public func optInWithBranch(experimentSlug: String, branch: String) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_opt_in_with_branch(self.pointer, experimentSlug.lower(), branch.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_opt_in_with_branch(self.pointer, + FfiConverterString.lower(experimentSlug), + FfiConverterString.lower(branch), $0) + } + ) } public func optOut(experimentSlug: String) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_opt_out(self.pointer, experimentSlug.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_opt_out(self.pointer, + FfiConverterString.lower(experimentSlug), $0) + } + ) } public func resetTelemetryIdentifiers(newRandomizationUnits: AvailableRandomizationUnits) throws -> [EnrollmentChangeEvent] { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_reset_telemetry_identifiers(self.pointer, newRandomizationUnits.lower(), $0) - } - return try FfiConverterSequenceRecordEnrollmentChangeEvent.lift(_retval) + return try FfiConverterSequenceTypeEnrollmentChangeEvent.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_reset_telemetry_identifiers(self.pointer, + FfiConverterTypeAvailableRandomizationUnits.lower(newRandomizationUnits), $0) + } + ) } - public func createTargetingHelper(additionalContext: String? = nil) throws -> NimbusTargetingHelper { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_create_targeting_helper(self.pointer, FfiConverterOptionJsonObject.lower(additionalContext), $0) - } - return try NimbusTargetingHelper.lift(_retval) + public func createTargetingHelper(additionalContext: JsonObject? = nil) throws -> NimbusTargetingHelper { + return try FfiConverterTypeNimbusTargetingHelper.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_create_targeting_helper(self.pointer, + FfiConverterOptionTypeJsonObject.lower(additionalContext), $0) + } + ) } - public func createStringHelper(additionalContext: String? = nil) throws -> NimbusStringHelper { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusClient_create_string_helper(self.pointer, FfiConverterOptionJsonObject.lower(additionalContext), $0) - } - return try NimbusStringHelper.lift(_retval) + public func createStringHelper(additionalContext: JsonObject? = nil) throws -> NimbusStringHelper { + return try FfiConverterTypeNimbusStringHelper.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusClient_create_string_helper(self.pointer, + FfiConverterOptionTypeJsonObject.lower(additionalContext), $0) + } + ) } } -private extension NimbusClient { +private struct FfiConverterTypeNimbusClient: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = NimbusClient - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> NimbusClient { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -607,27 +543,21 @@ private extension NimbusClient { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: NimbusClient, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NimbusClient { + return NimbusClient(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: NimbusClient) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension NimbusClient: ViaFfi, Serializable {} - public protocol NimbusTargetingHelperProtocol { func evalJexl(expression: String) throws -> Bool } @@ -636,29 +566,32 @@ public class NimbusTargetingHelper: NimbusTargetingHelperProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { - try! rustCall { ffi_nimbus_302d_NimbusTargetingHelper_object_free(pointer, $0) } + try! rustCall { ffi_nimbus_e97_NimbusTargetingHelper_object_free(pointer, $0) } } public func evalJexl(expression: String) throws -> Bool { - let _retval = try - rustCallWithError(NimbusError.self) { - nimbus_302d_NimbusTargetingHelper_eval_jexl(self.pointer, expression.lower(), $0) - } - return try Bool.lift(_retval) + return try FfiConverterBool.lift( + try + rustCallWithError(FfiConverterTypeNimbusError.self) { + nimbus_e97_NimbusTargetingHelper_eval_jexl(self.pointer, + FfiConverterString.lower(expression), $0) + } + ) } } -private extension NimbusTargetingHelper { +private struct FfiConverterTypeNimbusTargetingHelper: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = NimbusTargetingHelper - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> NimbusTargetingHelper { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -669,27 +602,21 @@ private extension NimbusTargetingHelper { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: NimbusTargetingHelper, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NimbusTargetingHelper { + return NimbusTargetingHelper(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: NimbusTargetingHelper) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension NimbusTargetingHelper: ViaFfi, Serializable {} - public protocol NimbusStringHelperProtocol { func stringFormat(template: String, uuid: String?) -> String func getUuid(template: String) -> String? @@ -699,37 +626,43 @@ public class NimbusStringHelper: NimbusStringHelperProtocol { fileprivate let pointer: UnsafeMutableRawPointer // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `ViaFfi` without making this `required` and we can't + // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { - try! rustCall { ffi_nimbus_302d_NimbusStringHelper_object_free(pointer, $0) } + try! rustCall { ffi_nimbus_e97_NimbusStringHelper_object_free(pointer, $0) } } public func stringFormat(template: String, uuid: String? = nil) -> String { - let _retval = try! - rustCall { - nimbus_302d_NimbusStringHelper_string_format(self.pointer, template.lower(), FfiConverterOptionString.lower(uuid), $0) - } - return try! String.lift(_retval) + return try! FfiConverterString.lift( + try! + rustCall { + nimbus_e97_NimbusStringHelper_string_format(self.pointer, + FfiConverterString.lower(template), + FfiConverterOptionString.lower(uuid), $0) + } + ) } public func getUuid(template: String) -> String? { - let _retval = try! - rustCall { - nimbus_302d_NimbusStringHelper_get_uuid(self.pointer, template.lower(), $0) - } - return try! FfiConverterOptionString.lift(_retval) + return try! FfiConverterOptionString.lift( + try! + rustCall { + nimbus_e97_NimbusStringHelper_get_uuid(self.pointer, + FfiConverterString.lower(template), $0) + } + ) } } -private extension NimbusStringHelper { +private struct FfiConverterTypeNimbusStringHelper: FfiConverter { typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = NimbusStringHelper - static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> NimbusStringHelper { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -740,27 +673,21 @@ private extension NimbusStringHelper { return try lift(ptr!) } - func write(into buf: Writer) { + static func write(_ value: NimbusStringHelper, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. - buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower())))) + buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Self { - return Self(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NimbusStringHelper { + return NimbusStringHelper(unsafeFromRawPointer: pointer) } - func lower() -> UnsafeMutableRawPointer { - return pointer + static func lower(_ value: NimbusStringHelper) -> UnsafeMutableRawPointer { + return value.pointer } } -// Ideally this would be `fileprivate`, but Swift says: -// """ -// 'private' modifier cannot be used with extensions that declare protocol conformances -// """ -extension NimbusStringHelper: ViaFfi, Serializable {} - public struct AppContext { public var appName: String public var appId: String @@ -874,12 +801,12 @@ extension AppContext: Equatable, Hashable { } } -private extension AppContext { - static func read(from buf: Reader) throws -> AppContext { +private struct FfiConverterTypeAppContext: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AppContext { return try AppContext( - appName: String.read(from: buf), - appId: String.read(from: buf), - channel: String.read(from: buf), + appName: FfiConverterString.read(from: buf), + appId: FfiConverterString.read(from: buf), + channel: FfiConverterString.read(from: buf), appVersion: FfiConverterOptionString.read(from: buf), appBuild: FfiConverterOptionString.read(from: buf), architecture: FfiConverterOptionString.read(from: buf), @@ -892,32 +819,30 @@ private extension AppContext { debugTag: FfiConverterOptionString.read(from: buf), installationDate: FfiConverterOptionInt64.read(from: buf), homeDirectory: FfiConverterOptionString.read(from: buf), - customTargetingAttributes: FfiConverterOptionDictionaryString.read(from: buf) + customTargetingAttributes: FfiConverterOptionDictionaryStringString.read(from: buf) ) } - func write(into buf: Writer) { - appName.write(into: buf) - appId.write(into: buf) - channel.write(into: buf) - FfiConverterOptionString.write(appVersion, into: buf) - FfiConverterOptionString.write(appBuild, into: buf) - FfiConverterOptionString.write(architecture, into: buf) - FfiConverterOptionString.write(deviceManufacturer, into: buf) - FfiConverterOptionString.write(deviceModel, into: buf) - FfiConverterOptionString.write(locale, into: buf) - FfiConverterOptionString.write(os, into: buf) - FfiConverterOptionString.write(osVersion, into: buf) - FfiConverterOptionString.write(androidSdkVersion, into: buf) - FfiConverterOptionString.write(debugTag, into: buf) - FfiConverterOptionInt64.write(installationDate, into: buf) - FfiConverterOptionString.write(homeDirectory, into: buf) - FfiConverterOptionDictionaryString.write(customTargetingAttributes, into: buf) + fileprivate static func write(_ value: AppContext, into buf: Writer) { + FfiConverterString.write(value.appName, into: buf) + FfiConverterString.write(value.appId, into: buf) + FfiConverterString.write(value.channel, into: buf) + FfiConverterOptionString.write(value.appVersion, into: buf) + FfiConverterOptionString.write(value.appBuild, into: buf) + FfiConverterOptionString.write(value.architecture, into: buf) + FfiConverterOptionString.write(value.deviceManufacturer, into: buf) + FfiConverterOptionString.write(value.deviceModel, into: buf) + FfiConverterOptionString.write(value.locale, into: buf) + FfiConverterOptionString.write(value.os, into: buf) + FfiConverterOptionString.write(value.osVersion, into: buf) + FfiConverterOptionString.write(value.androidSdkVersion, into: buf) + FfiConverterOptionString.write(value.debugTag, into: buf) + FfiConverterOptionInt64.write(value.installationDate, into: buf) + FfiConverterOptionString.write(value.homeDirectory, into: buf) + FfiConverterOptionDictionaryStringString.write(value.customTargetingAttributes, into: buf) } } -extension AppContext: ViaFfiUsingByteBuffer, ViaFfi {} - public struct EnrolledExperiment { public var featureIds: [String] public var slug: String @@ -971,30 +896,28 @@ extension EnrolledExperiment: Equatable, Hashable { } } -private extension EnrolledExperiment { - static func read(from buf: Reader) throws -> EnrolledExperiment { +private struct FfiConverterTypeEnrolledExperiment: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> EnrolledExperiment { return try EnrolledExperiment( featureIds: FfiConverterSequenceString.read(from: buf), - slug: String.read(from: buf), - userFacingName: String.read(from: buf), - userFacingDescription: String.read(from: buf), - branchSlug: String.read(from: buf), - enrollmentId: String.read(from: buf) + slug: FfiConverterString.read(from: buf), + userFacingName: FfiConverterString.read(from: buf), + userFacingDescription: FfiConverterString.read(from: buf), + branchSlug: FfiConverterString.read(from: buf), + enrollmentId: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterSequenceString.write(featureIds, into: buf) - slug.write(into: buf) - userFacingName.write(into: buf) - userFacingDescription.write(into: buf) - branchSlug.write(into: buf) - enrollmentId.write(into: buf) + fileprivate static func write(_ value: EnrolledExperiment, into buf: Writer) { + FfiConverterSequenceString.write(value.featureIds, into: buf) + FfiConverterString.write(value.slug, into: buf) + FfiConverterString.write(value.userFacingName, into: buf) + FfiConverterString.write(value.userFacingDescription, into: buf) + FfiConverterString.write(value.branchSlug, into: buf) + FfiConverterString.write(value.enrollmentId, into: buf) } } -extension EnrolledExperiment: ViaFfiUsingByteBuffer, ViaFfi {} - public struct AvailableExperiment { public var slug: String public var userFacingName: String @@ -1042,28 +965,26 @@ extension AvailableExperiment: Equatable, Hashable { } } -private extension AvailableExperiment { - static func read(from buf: Reader) throws -> AvailableExperiment { +private struct FfiConverterTypeAvailableExperiment: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AvailableExperiment { return try AvailableExperiment( - slug: String.read(from: buf), - userFacingName: String.read(from: buf), - userFacingDescription: String.read(from: buf), - branches: FfiConverterSequenceRecordExperimentBranch.read(from: buf), + slug: FfiConverterString.read(from: buf), + userFacingName: FfiConverterString.read(from: buf), + userFacingDescription: FfiConverterString.read(from: buf), + branches: FfiConverterSequenceTypeExperimentBranch.read(from: buf), referenceBranch: FfiConverterOptionString.read(from: buf) ) } - func write(into buf: Writer) { - slug.write(into: buf) - userFacingName.write(into: buf) - userFacingDescription.write(into: buf) - FfiConverterSequenceRecordExperimentBranch.write(branches, into: buf) - FfiConverterOptionString.write(referenceBranch, into: buf) + fileprivate static func write(_ value: AvailableExperiment, into buf: Writer) { + FfiConverterString.write(value.slug, into: buf) + FfiConverterString.write(value.userFacingName, into: buf) + FfiConverterString.write(value.userFacingDescription, into: buf) + FfiConverterSequenceTypeExperimentBranch.write(value.branches, into: buf) + FfiConverterOptionString.write(value.referenceBranch, into: buf) } } -extension AvailableExperiment: ViaFfiUsingByteBuffer, ViaFfi {} - public struct ExperimentBranch { public var slug: String public var ratio: Int32 @@ -1093,22 +1014,20 @@ extension ExperimentBranch: Equatable, Hashable { } } -private extension ExperimentBranch { - static func read(from buf: Reader) throws -> ExperimentBranch { +private struct FfiConverterTypeExperimentBranch: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> ExperimentBranch { return try ExperimentBranch( - slug: String.read(from: buf), - ratio: Int32.read(from: buf) + slug: FfiConverterString.read(from: buf), + ratio: FfiConverterInt32.read(from: buf) ) } - func write(into buf: Writer) { - slug.write(into: buf) - ratio.write(into: buf) + fileprivate static func write(_ value: ExperimentBranch, into buf: Writer) { + FfiConverterString.write(value.slug, into: buf) + FfiConverterInt32.write(value.ratio, into: buf) } } -extension ExperimentBranch: ViaFfiUsingByteBuffer, ViaFfi {} - public struct RemoteSettingsConfig { public var serverUrl: String public var collectionName: String @@ -1138,22 +1057,20 @@ extension RemoteSettingsConfig: Equatable, Hashable { } } -private extension RemoteSettingsConfig { - static func read(from buf: Reader) throws -> RemoteSettingsConfig { +private struct FfiConverterTypeRemoteSettingsConfig: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> RemoteSettingsConfig { return try RemoteSettingsConfig( - serverUrl: String.read(from: buf), - collectionName: String.read(from: buf) + serverUrl: FfiConverterString.read(from: buf), + collectionName: FfiConverterString.read(from: buf) ) } - func write(into buf: Writer) { - serverUrl.write(into: buf) - collectionName.write(into: buf) + fileprivate static func write(_ value: RemoteSettingsConfig, into buf: Writer) { + FfiConverterString.write(value.serverUrl, into: buf) + FfiConverterString.write(value.collectionName, into: buf) } } -extension RemoteSettingsConfig: ViaFfiUsingByteBuffer, ViaFfi {} - public struct AvailableRandomizationUnits { public var clientId: String? public var dummy: Int8 @@ -1183,22 +1100,20 @@ extension AvailableRandomizationUnits: Equatable, Hashable { } } -private extension AvailableRandomizationUnits { - static func read(from buf: Reader) throws -> AvailableRandomizationUnits { +private struct FfiConverterTypeAvailableRandomizationUnits: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> AvailableRandomizationUnits { return try AvailableRandomizationUnits( clientId: FfiConverterOptionString.read(from: buf), - dummy: Int8.read(from: buf) + dummy: FfiConverterInt8.read(from: buf) ) } - func write(into buf: Writer) { - FfiConverterOptionString.write(clientId, into: buf) - dummy.write(into: buf) + fileprivate static func write(_ value: AvailableRandomizationUnits, into buf: Writer) { + FfiConverterOptionString.write(value.clientId, into: buf) + FfiConverterInt8.write(value.dummy, into: buf) } } -extension AvailableRandomizationUnits: ViaFfiUsingByteBuffer, ViaFfi {} - public struct EnrollmentChangeEvent { public var experimentSlug: String public var branchSlug: String @@ -1246,28 +1161,26 @@ extension EnrollmentChangeEvent: Equatable, Hashable { } } -private extension EnrollmentChangeEvent { - static func read(from buf: Reader) throws -> EnrollmentChangeEvent { +private struct FfiConverterTypeEnrollmentChangeEvent: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> EnrollmentChangeEvent { return try EnrollmentChangeEvent( - experimentSlug: String.read(from: buf), - branchSlug: String.read(from: buf), - enrollmentId: String.read(from: buf), + experimentSlug: FfiConverterString.read(from: buf), + branchSlug: FfiConverterString.read(from: buf), + enrollmentId: FfiConverterString.read(from: buf), reason: FfiConverterOptionString.read(from: buf), - change: EnrollmentChangeEventType.read(from: buf) + change: FfiConverterTypeEnrollmentChangeEventType.read(from: buf) ) } - func write(into buf: Writer) { - experimentSlug.write(into: buf) - branchSlug.write(into: buf) - enrollmentId.write(into: buf) - FfiConverterOptionString.write(reason, into: buf) - change.write(into: buf) + fileprivate static func write(_ value: EnrollmentChangeEvent, into buf: Writer) { + FfiConverterString.write(value.experimentSlug, into: buf) + FfiConverterString.write(value.branchSlug, into: buf) + FfiConverterString.write(value.enrollmentId, into: buf) + FfiConverterOptionString.write(value.reason, into: buf) + FfiConverterTypeEnrollmentChangeEventType.write(value.change, into: buf) } } -extension EnrollmentChangeEvent: ViaFfiUsingByteBuffer, ViaFfi {} - public enum NimbusError { // Simple error enums only carry a message case InvalidPersistedData(message: String) @@ -1336,170 +1249,172 @@ public enum NimbusError { case VersionParsingError(message: String) } -extension NimbusError: ViaFfiUsingByteBuffer, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> NimbusError { +private struct FfiConverterTypeNimbusError: FfiConverterRustBuffer { + typealias SwiftType = NimbusError + + static func read(from buf: Reader) throws -> NimbusError { let variant: Int32 = try buf.readInt() switch variant { case 1: return .InvalidPersistedData( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 2: return .RkvError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 3: return .IoError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 4: return .JsonError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 5: return .EvaluationError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 6: return .InvalidExpression( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 7: return .InvalidFraction( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 8: return .TryFromSliceError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 9: return .EmptyRatiosError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 10: return .OutOfBoundsError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 11: return .UrlParsingError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 12: return .RequestError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 13: return .ResponseError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 14: return .UuidError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 15: return .InvalidExperimentFormat( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 16: return .InvalidPath( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 17: return .InternalError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 18: return .NoSuchExperiment( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 19: return .NoSuchBranch( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 20: return .BackoffError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 21: return .DatabaseNotReady( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) case 22: return .VersionParsingError( - message: try String.read(from: buf) + message: try FfiConverterString.read(from: buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } - fileprivate func write(into buf: Writer) { - switch self { + static func write(_ value: NimbusError, into buf: Writer) { + switch value { case let .InvalidPersistedData(message): buf.writeInt(Int32(1)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .RkvError(message): buf.writeInt(Int32(2)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .IoError(message): buf.writeInt(Int32(3)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .JsonError(message): buf.writeInt(Int32(4)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .EvaluationError(message): buf.writeInt(Int32(5)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidExpression(message): buf.writeInt(Int32(6)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidFraction(message): buf.writeInt(Int32(7)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .TryFromSliceError(message): buf.writeInt(Int32(8)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .EmptyRatiosError(message): buf.writeInt(Int32(9)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .OutOfBoundsError(message): buf.writeInt(Int32(10)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UrlParsingError(message): buf.writeInt(Int32(11)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .RequestError(message): buf.writeInt(Int32(12)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .ResponseError(message): buf.writeInt(Int32(13)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .UuidError(message): buf.writeInt(Int32(14)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidExperimentFormat(message): buf.writeInt(Int32(15)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InvalidPath(message): buf.writeInt(Int32(16)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .InternalError(message): buf.writeInt(Int32(17)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .NoSuchExperiment(message): buf.writeInt(Int32(18)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .NoSuchBranch(message): buf.writeInt(Int32(19)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .BackoffError(message): buf.writeInt(Int32(20)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .DatabaseNotReady(message): buf.writeInt(Int32(21)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) case let .VersionParsingError(message): buf.writeInt(Int32(22)) - message.write(into: buf) + FfiConverterString.write(message, into: buf) } } } @@ -1507,90 +1422,90 @@ extension NimbusError: ViaFfiUsingByteBuffer, ViaFfi { extension NimbusError: Equatable, Hashable {} extension NimbusError: Error {} -private enum FfiConverterTypeJsonObject { - fileprivate static func read(_ buf: Reader) throws -> String { - return try String.read(from: buf) - } - - fileprivate static func write(_ value: String, _ buf: Writer) { - return value.write(into: buf) - } - fileprivate static func lift(_ value: RustBuffer) throws -> String { - return try String.lift(value) - } - - fileprivate static func lower(_ value: String) -> RustBuffer { - return value.lower() - } -} +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias JsonObject = String +private typealias FfiConverterTypeJsonObject = FfiConverterString +private struct FfiConverterInt8: FfiConverterPrimitive { + typealias FfiType = Int8 + typealias SwiftType = Int8 -extension Int8: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> Int8 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int8, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Int32: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterInt32: FfiConverterPrimitive { + typealias FfiType = Int32 + typealias SwiftType = Int32 + + static func read(from buf: Reader) throws -> Int32 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int32, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Int64: Primitive, ViaFfi { - fileprivate static func read(from buf: Reader) throws -> Self { +private struct FfiConverterInt64: FfiConverterPrimitive { + typealias FfiType = Int64 + typealias SwiftType = Int64 + + static func read(from buf: Reader) throws -> Int64 { return try lift(buf.readInt()) } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func write(_ value: Int64, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension Bool: ViaFfi { - fileprivate typealias FfiType = Int8 +private struct FfiConverterBool: FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool - fileprivate static func read(from buf: Reader) throws -> Self { - return try lift(buf.readInt()) + static func lift(_ value: Int8) throws -> Bool { + return value != 0 } - fileprivate func write(into buf: Writer) { - buf.writeInt(lower()) + static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 } - fileprivate static func lift(_ v: FfiType) throws -> Self { - return v != 0 + static func read(from buf: Reader) throws -> Bool { + return try lift(buf.readInt()) } - fileprivate func lower() -> FfiType { - return self ? 1 : 0 + static func write(_ value: Bool, into buf: Writer) { + buf.writeInt(lower(value)) } } -extension String: ViaFfi { - fileprivate typealias FfiType = RustBuffer +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer - fileprivate static func lift(_ v: FfiType) throws -> Self { + static func lift(_ value: RustBuffer) throws -> String { defer { - v.deallocate() + value.deallocate() } - if v.data == nil { + if value.data == nil { return String() } - let bytes = UnsafeBufferPointer(start: v.data!, count: Int(v.len)) + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) return String(bytes: bytes, encoding: String.Encoding.utf8)! } - fileprivate func lower() -> FfiType { - return utf8CString.withUnsafeBufferPointer { ptr in + static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in // The swift string gives us int8_t, we want uint8_t. ptr.withMemoryRebound(to: UInt8.self) { ptr in // The swift string gives us a trailing null byte, we don't want it. @@ -1600,15 +1515,15 @@ extension String: ViaFfi { } } - fileprivate static func read(from buf: Reader) throws -> Self { + static func read(from buf: Reader) throws -> String { let len: Int32 = try buf.readInt() return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)! } - fileprivate func write(into buf: Writer) { - let len = Int32(utf8.count) + static func write(_ value: String, into buf: Writer) { + let len = Int32(value.utf8.count) buf.writeInt(len) - buf.writeBytes(utf8) + buf.writeBytes(value.utf8) } } @@ -1625,181 +1540,241 @@ extension String: ViaFfi { // Helper code for EnrollmentChangeEventType enum is found in EnumTemplate.swift // Helper code for NimbusError error is found in ErrorTemplate.swift -private enum FfiConverterOptionInt64: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionInt64: FfiConverterRustBuffer { typealias SwiftType = Int64? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterInt64.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try Int64.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterInt64.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try String.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionRecordRemoteSettingsConfig: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionTypeRemoteSettingsConfig: FfiConverterRustBuffer { typealias SwiftType = RemoteSettingsConfig? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - item.write(into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeRemoteSettingsConfig.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try RemoteSettingsConfig.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeRemoteSettingsConfig.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionDictionaryString: FfiConverterUsingByteBuffer { +private struct FfiConverterOptionDictionaryStringString: FfiConverterRustBuffer { typealias SwiftType = [String: String]? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterDictionaryString.write(item, into: buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterDictionaryStringString.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterDictionaryString.read(from: buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterDictionaryStringString.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterOptionJsonObject: FfiConverterUsingByteBuffer { - typealias SwiftType = String? +private struct FfiConverterOptionTypeJsonObject: FfiConverterRustBuffer { + typealias SwiftType = JsonObject? static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterOptional.write(value, into: buf) { item, buf in - FfiConverterTypeJsonObject.write(item, buf) + guard let value = value else { + buf.writeInt(Int8(0)) + return } + buf.writeInt(Int8(1)) + FfiConverterTypeJsonObject.write(value, into: buf) } static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterOptional.read(from: buf) { buf in - try FfiConverterTypeJsonObject.read(buf) + switch try buf.readInt() as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeJsonObject.read(from: buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } -private enum FfiConverterSequenceString: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterString.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try String.read(from: buf) + static func read(from buf: Reader) throws -> [String] { + let len: Int32 = try buf.readInt() + var seq = [String]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterString.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordAvailableExperiment: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeAvailableExperiment: FfiConverterRustBuffer { typealias SwiftType = [AvailableExperiment] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [AvailableExperiment], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeAvailableExperiment.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try AvailableExperiment.read(from: buf) + static func read(from buf: Reader) throws -> [AvailableExperiment] { + let len: Int32 = try buf.readInt() + var seq = [AvailableExperiment]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeAvailableExperiment.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordEnrolledExperiment: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeEnrolledExperiment: FfiConverterRustBuffer { typealias SwiftType = [EnrolledExperiment] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [EnrolledExperiment], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeEnrolledExperiment.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try EnrolledExperiment.read(from: buf) + static func read(from buf: Reader) throws -> [EnrolledExperiment] { + let len: Int32 = try buf.readInt() + var seq = [EnrolledExperiment]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeEnrolledExperiment.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordEnrollmentChangeEvent: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeEnrollmentChangeEvent: FfiConverterRustBuffer { typealias SwiftType = [EnrollmentChangeEvent] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [EnrollmentChangeEvent], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeEnrollmentChangeEvent.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try EnrollmentChangeEvent.read(from: buf) + static func read(from buf: Reader) throws -> [EnrollmentChangeEvent] { + let len: Int32 = try buf.readInt() + var seq = [EnrollmentChangeEvent]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeEnrollmentChangeEvent.read(from: buf)) } + return seq } } -private enum FfiConverterSequenceRecordExperimentBranch: FfiConverterUsingByteBuffer { +private struct FfiConverterSequenceTypeExperimentBranch: FfiConverterRustBuffer { typealias SwiftType = [ExperimentBranch] - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterSequence.write(value, into: buf) { item, buf in - item.write(into: buf) + static func write(_ value: [ExperimentBranch], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for item in value { + FfiConverterTypeExperimentBranch.write(item, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterSequence.read(from: buf) { buf in - try ExperimentBranch.read(from: buf) + static func read(from buf: Reader) throws -> [ExperimentBranch] { + let len: Int32 = try buf.readInt() + var seq = [ExperimentBranch]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeExperimentBranch.read(from: buf)) } + return seq } } -private enum FfiConverterDictionaryString: FfiConverterUsingByteBuffer { - typealias SwiftType = [String: String] - - static func write(_ value: SwiftType, into buf: Writer) { - FfiConverterDictionary.write(value, into: buf) { key, value, buf in - key.write(into: buf) - value.write(into: buf) +private struct FfiConverterDictionaryStringString: FfiConverterRustBuffer { + fileprivate static func write(_ value: [String: String], into buf: Writer) { + let len = Int32(value.count) + buf.writeInt(len) + for (key, value) in value { + FfiConverterString.write(key, into: buf) + FfiConverterString.write(value, into: buf) } } - static func read(from buf: Reader) throws -> SwiftType { - try FfiConverterDictionary.read(from: buf) { buf in - (try String.read(from: buf), - try String.read(from: buf)) + fileprivate static func read(from buf: Reader) throws -> [String: String] { + let len: Int32 = try buf.readInt() + var dict = [String: String]() + dict.reserveCapacity(Int(len)) + for _ in 0 ..< len { + let key = try FfiConverterString.read(from: buf) + let value = try FfiConverterString.read(from: buf) + dict[key] = value } + return dict } } diff --git a/swift-source/focus/Generated/nimbusFFI.h b/swift-source/focus/Generated/nimbusFFI.h index 7463cdd3..bdd9ca26 100644 --- a/swift-source/focus/Generated/nimbusFFI.h +++ b/swift-source/focus/Generated/nimbusFFI.h @@ -46,115 +46,115 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_nimbus_302d_NimbusClient_object_free( +void ffi_nimbus_e97_NimbusClient_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull nimbus_302d_NimbusClient_new( +void*_Nonnull nimbus_e97_NimbusClient_new( RustBuffer app_ctx,RustBuffer dbpath,RustBuffer remote_settings_config,RustBuffer available_randomization_units, RustCallStatus *_Nonnull out_status ); -void nimbus_302d_NimbusClient_initialize( +void nimbus_e97_NimbusClient_initialize( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_experiment_branch( +RustBuffer nimbus_e97_NimbusClient_get_experiment_branch( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_feature_config_variables( +RustBuffer nimbus_e97_NimbusClient_get_feature_config_variables( void*_Nonnull ptr,RustBuffer feature_id, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_experiment_branches( +RustBuffer nimbus_e97_NimbusClient_get_experiment_branches( void*_Nonnull ptr,RustBuffer experiment_slug, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_active_experiments( +RustBuffer nimbus_e97_NimbusClient_get_active_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_get_available_experiments( +RustBuffer nimbus_e97_NimbusClient_get_available_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -int8_t nimbus_302d_NimbusClient_get_global_user_participation( +int8_t nimbus_e97_NimbusClient_get_global_user_participation( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_set_global_user_participation( +RustBuffer nimbus_e97_NimbusClient_set_global_user_participation( void*_Nonnull ptr,int8_t opt_in, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_update_experiments( +RustBuffer nimbus_e97_NimbusClient_update_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void nimbus_302d_NimbusClient_fetch_experiments( +void nimbus_e97_NimbusClient_fetch_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_apply_pending_experiments( +RustBuffer nimbus_e97_NimbusClient_apply_pending_experiments( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void nimbus_302d_NimbusClient_set_experiments_locally( +void nimbus_e97_NimbusClient_set_experiments_locally( void*_Nonnull ptr,RustBuffer experiments_json, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_opt_in_with_branch( +RustBuffer nimbus_e97_NimbusClient_opt_in_with_branch( void*_Nonnull ptr,RustBuffer experiment_slug,RustBuffer branch, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_opt_out( +RustBuffer nimbus_e97_NimbusClient_opt_out( void*_Nonnull ptr,RustBuffer experiment_slug, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusClient_reset_telemetry_identifiers( +RustBuffer nimbus_e97_NimbusClient_reset_telemetry_identifiers( void*_Nonnull ptr,RustBuffer new_randomization_units, RustCallStatus *_Nonnull out_status ); -void*_Nonnull nimbus_302d_NimbusClient_create_targeting_helper( +void*_Nonnull nimbus_e97_NimbusClient_create_targeting_helper( void*_Nonnull ptr,RustBuffer additional_context, RustCallStatus *_Nonnull out_status ); -void*_Nonnull nimbus_302d_NimbusClient_create_string_helper( +void*_Nonnull nimbus_e97_NimbusClient_create_string_helper( void*_Nonnull ptr,RustBuffer additional_context, RustCallStatus *_Nonnull out_status ); -void ffi_nimbus_302d_NimbusTargetingHelper_object_free( +void ffi_nimbus_e97_NimbusTargetingHelper_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -int8_t nimbus_302d_NimbusTargetingHelper_eval_jexl( +int8_t nimbus_e97_NimbusTargetingHelper_eval_jexl( void*_Nonnull ptr,RustBuffer expression, RustCallStatus *_Nonnull out_status ); -void ffi_nimbus_302d_NimbusStringHelper_object_free( +void ffi_nimbus_e97_NimbusStringHelper_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusStringHelper_string_format( +RustBuffer nimbus_e97_NimbusStringHelper_string_format( void*_Nonnull ptr,RustBuffer template,RustBuffer uuid, RustCallStatus *_Nonnull out_status ); -RustBuffer nimbus_302d_NimbusStringHelper_get_uuid( +RustBuffer nimbus_e97_NimbusStringHelper_get_uuid( void*_Nonnull ptr,RustBuffer template, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_nimbus_302d_rustbuffer_alloc( +RustBuffer ffi_nimbus_e97_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_nimbus_302d_rustbuffer_from_bytes( +RustBuffer ffi_nimbus_e97_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_nimbus_302d_rustbuffer_free( +void ffi_nimbus_e97_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_nimbus_302d_rustbuffer_reserve( +RustBuffer ffi_nimbus_e97_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status );