diff --git a/AutomergeUniffi/automerge.swift b/AutomergeUniffi/automerge.swift index 67c0e5b4..f4883839 100644 --- a/AutomergeUniffi/automerge.swift +++ b/AutomergeUniffi/automerge.swift @@ -11,7 +11,7 @@ import Foundation import automergeFFI #endif -private extension RustBuffer { +fileprivate extension RustBuffer { // Allocate a new buffer, copying the contents of a `UInt8` array. init(bytes: [UInt8]) { let rbuf = bytes.withUnsafeBufferPointer { ptr in @@ -21,7 +21,7 @@ private extension RustBuffer { } static func empty() -> RustBuffer { - RustBuffer(capacity: 0, len: 0, data: nil) + RustBuffer(capacity: 0, len:0, data: nil) } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { @@ -35,7 +35,7 @@ private extension RustBuffer { } } -private extension ForeignBytes { +fileprivate extension ForeignBytes { init(bufferPointer: UnsafeBufferPointer) { self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) } @@ -48,7 +48,7 @@ private extension ForeignBytes { // Helper classes/extensions that don't change. // Someday, this will be in a library of its own. -private extension Data { +fileprivate extension Data { init(rustBuffer: RustBuffer) { // TODO: This copies the buffer. Can we read directly from a // Rust buffer? @@ -70,15 +70,15 @@ private extension Data { // // Instead, the read() method and these helper functions input a tuple of data -private func createReader(data: Data) -> (data: Data, offset: Data.Index) { +fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) { (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. -private func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { - let range = reader.offset ..< reader.offset + MemoryLayout.size +fileprivate func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { + let range = reader.offset...size guard reader.data.count >= range.upperBound else { throw UniffiInternalError.bufferOverflow } @@ -88,50 +88,50 @@ private func readInt(_ reader: inout (data: Data, offset: return value as! T } var value: T = 0 - let _ = withUnsafeMutableBytes(of: &value) { reader.data.copyBytes(to: $0, from: range) } + let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)}) reader.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 -private func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> [UInt8] { - let range = reader.offset ..< (reader.offset + count) +fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array { + let range = reader.offset..<(reader.offset+count) guard reader.data.count >= range.upperBound else { throw UniffiInternalError.bufferOverflow } var value = [UInt8](repeating: 0, count: count) - value.withUnsafeMutableBufferPointer { buffer in + value.withUnsafeMutableBufferPointer({ buffer in reader.data.copyBytes(to: buffer, from: range) - } + }) reader.offset = range.upperBound return value } // Reads a float at the current offset. -private func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { - try Float(bitPattern: readInt(&reader)) +fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { + return Float(bitPattern: try readInt(&reader)) } // Reads a float at the current offset. -private func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { - try Double(bitPattern: readInt(&reader)) +fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { + return Double(bitPattern: try readInt(&reader)) } // Indicates if the offset has reached the end of the buffer. -private func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { - reader.offset < reader.data.count +fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { + return reader.offset < reader.data.count } // Define writer functionality. Normally this would be defined in a class or // struct, but we use standalone functions instead in order to make external // types work. See the above discussion on Readers for details. -private func createWriter() -> [UInt8] { - [] +fileprivate func createWriter() -> [UInt8] { + return [] } -private func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { +fileprivate func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { writer.append(contentsOf: byteArr) } @@ -139,22 +139,22 @@ private func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Seque // // Warning: make sure what you are trying to write // is in the correct type! -private func writeInt(_ writer: inout [UInt8], _ value: T) { +fileprivate func writeInt(_ writer: inout [UInt8], _ value: T) { var value = value.bigEndian withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } } -private func writeFloat(_ writer: inout [UInt8], _ value: Float) { +fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) { writeInt(&writer, value.bitPattern) } -private func writeDouble(_ writer: inout [UInt8], _ value: Double) { +fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) { writeInt(&writer, 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 { +fileprivate protocol FfiConverter { associatedtype FfiType associatedtype SwiftType @@ -165,21 +165,21 @@ private protocol FfiConverter { } // Types conforming to `Primitive` pass themselves directly over the FFI. -private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} +fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { } extension FfiConverterPrimitive { public static func lift(_ value: FfiType) throws -> SwiftType { - value + return value } public static func lower(_ value: SwiftType) -> FfiType { - value + 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 {} +fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} extension FfiConverterRustBuffer { public static func lift(_ buf: RustBuffer) throws -> SwiftType { @@ -193,15 +193,14 @@ extension FfiConverterRustBuffer { } public static func lower(_ value: SwiftType) -> RustBuffer { - var writer = createWriter() - write(value, into: &writer) - return RustBuffer(bytes: writer) + var writer = createWriter() + write(value, into: &writer) + return RustBuffer(bytes: writer) } } - // An error type for FFI errors. These errors occur at the UniFFI level, not // the library level. -private enum UniffiInternalError: LocalizedError { +fileprivate enum UniffiInternalError: LocalizedError { case bufferOverflow case incompleteData case unexpectedOptionalTag @@ -227,24 +226,24 @@ private enum UniffiInternalError: LocalizedError { } } -private extension NSLock { +fileprivate extension NSLock { func withLock(f: () throws -> T) rethrows -> T { - lock() + self.lock() defer { self.unlock() } return try f() } } -private let CALL_SUCCESS: Int8 = 0 -private let CALL_ERROR: Int8 = 1 -private let CALL_UNEXPECTED_ERROR: Int8 = 2 -private let CALL_CANCELLED: Int8 = 3 +fileprivate let CALL_SUCCESS: Int8 = 0 +fileprivate let CALL_ERROR: Int8 = 1 +fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2 +fileprivate let CALL_CANCELLED: Int8 = 3 -private extension RustCallStatus { +fileprivate extension RustCallStatus { init() { self.init( code: CALL_SUCCESS, - errorBuf: RustBuffer( + errorBuf: RustBuffer.init( capacity: 0, len: 0, data: nil @@ -259,8 +258,7 @@ private func rustCall(_ callback: (UnsafeMutablePointer) -> T private func rustCallWithError( _ errorHandler: @escaping (RustBuffer) throws -> Error, - _ callback: (UnsafeMutablePointer) -> T -) throws -> T { + _ callback: (UnsafeMutablePointer) -> T) throws -> T { try makeRustCall(callback, errorHandler: errorHandler) } @@ -269,7 +267,7 @@ private func makeRustCall( errorHandler: ((RustBuffer) throws -> Error)? ) throws -> T { uniffiEnsureInitialized() - var callStatus = RustCallStatus() + var callStatus = RustCallStatus.init() let returnedVal = callback(&callStatus) try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) return returnedVal @@ -280,44 +278,44 @@ private func uniffiCheckCallStatus( errorHandler: ((RustBuffer) throws -> Error)? ) throws { switch callStatus.code { - case CALL_SUCCESS: - return + case CALL_SUCCESS: + return - case CALL_ERROR: - if let errorHandler = errorHandler { - throw try errorHandler(callStatus.errorBuf) - } else { - callStatus.errorBuf.deallocate() - throw UniffiInternalError.unexpectedRustCallError - } + case CALL_ERROR: + if let errorHandler = errorHandler { + throw try errorHandler(callStatus.errorBuf) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.unexpectedRustCallError + } - case CALL_UNEXPECTED_ERROR: - // 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 try UniffiInternalError.rustPanic(FfiConverterString.lift(callStatus.errorBuf)) - } else { - callStatus.errorBuf.deallocate() - throw UniffiInternalError.rustPanic("Rust panic") - } + case CALL_UNEXPECTED_ERROR: + // 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") + } - case CALL_CANCELLED: - fatalError("Cancellation not supported yet") + case CALL_CANCELLED: + fatalError("Cancellation not supported yet") - default: - throw UniffiInternalError.unexpectedRustCallStatusCode + default: + throw UniffiInternalError.unexpectedRustCallStatusCode } } private func uniffiTraitInterfaceCall( callStatus: UnsafeMutablePointer, makeCall: () throws -> T, - writeReturn: (T) -> Void + writeReturn: (T) -> () ) { do { try writeReturn(makeCall()) - } catch { + } catch let error { callStatus.pointee.code = CALL_UNEXPECTED_ERROR callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) } @@ -326,7 +324,7 @@ private func uniffiTraitInterfaceCall( private func uniffiTraitInterfaceCallWithError( callStatus: UnsafeMutablePointer, makeCall: () throws -> T, - writeReturn: (T) -> Void, + writeReturn: (T) -> (), lowerError: (E) -> RustBuffer ) { do { @@ -339,8 +337,7 @@ private func uniffiTraitInterfaceCallWithError( callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) } } - -private class UniffiHandleMap { +fileprivate class UniffiHandleMap { private var map: [UInt64: T] = [:] private let lock = NSLock() private var currentHandle: UInt64 = 1 @@ -354,7 +351,7 @@ private class UniffiHandleMap { } } - func get(handle: UInt64) throws -> T { + func get(handle: UInt64) throws -> T { try lock.withLock { guard let obj = map[handle] else { throw UniffiInternalError.unexpectedStaleHandle @@ -374,18 +371,22 @@ private class UniffiHandleMap { } var count: Int { - map.count + get { + map.count + } } } + // Public interface members begin here. -private struct FfiConverterUInt8: FfiConverterPrimitive { + +fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { typealias FfiType = UInt8 typealias SwiftType = UInt8 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { - try lift(readInt(&buf)) + return try lift(readInt(&buf)) } public static func write(_ value: UInt8, into buf: inout [UInt8]) { @@ -393,12 +394,12 @@ private struct FfiConverterUInt8: FfiConverterPrimitive { } } -private struct FfiConverterUInt64: FfiConverterPrimitive { +fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { typealias FfiType = UInt64 typealias SwiftType = UInt64 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { - try lift(readInt(&buf)) + return try lift(readInt(&buf)) } public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -406,12 +407,12 @@ private struct FfiConverterUInt64: FfiConverterPrimitive { } } -private struct FfiConverterInt64: FfiConverterPrimitive { +fileprivate struct FfiConverterInt64: FfiConverterPrimitive { typealias FfiType = Int64 typealias SwiftType = Int64 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 { - try lift(readInt(&buf)) + return try lift(readInt(&buf)) } public static func write(_ value: Int64, into buf: inout [UInt8]) { @@ -419,12 +420,12 @@ private struct FfiConverterInt64: FfiConverterPrimitive { } } -private struct FfiConverterDouble: FfiConverterPrimitive { +fileprivate struct FfiConverterDouble: FfiConverterPrimitive { typealias FfiType = Double typealias SwiftType = Double public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Double { - try lift(readDouble(&buf)) + return try lift(readDouble(&buf)) } public static func write(_ value: Double, into buf: inout [UInt8]) { @@ -432,20 +433,20 @@ private struct FfiConverterDouble: FfiConverterPrimitive { } } -private struct FfiConverterBool: FfiConverter { +fileprivate struct FfiConverterBool : FfiConverter { typealias FfiType = Int8 typealias SwiftType = Bool public static func lift(_ value: Int8) throws -> Bool { - value != 0 + return value != 0 } public static func lower(_ value: Bool) -> Int8 { - value ? 1 : 0 + return value ? 1 : 0 } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { - try lift(readInt(&buf)) + return try lift(readInt(&buf)) } public static func write(_ value: Bool, into buf: inout [UInt8]) { @@ -453,7 +454,7 @@ private struct FfiConverterBool: FfiConverter { } } -private struct FfiConverterString: FfiConverter { +fileprivate struct FfiConverterString: FfiConverter { typealias SwiftType = String typealias FfiType = RustBuffer @@ -469,7 +470,7 @@ private struct FfiConverterString: FfiConverter { } public static func lower(_ value: String) -> RustBuffer { - value.utf8CString.withUnsafeBufferPointer { ptr in + 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. @@ -481,7 +482,7 @@ private struct FfiConverterString: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { let len: Int32 = try readInt(&buf) - return try String(bytes: readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! + return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! } public static func write(_ value: String, into buf: inout [UInt8]) { @@ -491,127 +492,133 @@ private struct FfiConverterString: FfiConverter { } } -public protocol DocProtocol: AnyObject { - func actorId() -> ActorId - - func applyEncodedChanges(changes: [UInt8]) throws - - func applyEncodedChangesWithPatches(changes: [UInt8]) throws -> [Patch] - - func changeByHash(hash: ChangeHash) -> Change? - - func changes() -> [ChangeHash] - - func commitWith(msg: String?, time: Int64) - - func cursor(obj: ObjId, position: UInt64) throws -> Cursor - - func cursorAt(obj: ObjId, position: UInt64, heads: [ChangeHash]) throws -> Cursor - - func cursorPosition(obj: ObjId, cursor: Cursor) throws -> UInt64 - - func cursorPositionAt(obj: ObjId, cursor: Cursor, heads: [ChangeHash]) throws -> UInt64 - - func deleteInList(obj: ObjId, index: UInt64) throws - - func deleteInMap(obj: ObjId, key: String) throws - - func encodeChangesSince(heads: [ChangeHash]) throws -> [UInt8] - - func encodeNewChanges() -> [UInt8] - - func fork() -> Doc - - func forkAt(heads: [ChangeHash]) throws -> Doc - - func generateSyncMessage(state: SyncState) -> [UInt8]? - - func getAllAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash]) throws -> [Value] - - func getAllAtInMap(obj: ObjId, key: String, heads: [ChangeHash]) throws -> [Value] - - func getAllInList(obj: ObjId, index: UInt64) throws -> [Value] - - func getAllInMap(obj: ObjId, key: String) throws -> [Value] - - func getAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash]) throws -> Value? - - func getAtInMap(obj: ObjId, key: String, heads: [ChangeHash]) throws -> Value? - - func getInList(obj: ObjId, index: UInt64) throws -> Value? - - func getInMap(obj: ObjId, key: String) throws -> Value? - - func heads() -> [ChangeHash] - - func incrementInList(obj: ObjId, index: UInt64, by: Int64) throws - - func incrementInMap(obj: ObjId, key: String, by: Int64) throws - - func insertInList(obj: ObjId, index: UInt64, value: ScalarValue) throws - - func insertObjectInList(obj: ObjId, index: UInt64, objType: ObjType) throws -> ObjId - - func length(obj: ObjId) -> UInt64 - - func lengthAt(obj: ObjId, heads: [ChangeHash]) -> UInt64 - - func mapEntries(obj: ObjId) throws -> [KeyValue] - - func mapEntriesAt(obj: ObjId, heads: [ChangeHash]) throws -> [KeyValue] - func mapKeys(obj: ObjId) -> [String] - func mapKeysAt(obj: ObjId, heads: [ChangeHash]) -> [String] - func mark(obj: ObjId, start: UInt64, end: UInt64, expand: ExpandMark, name: String, value: ScalarValue) throws - - func marks(obj: ObjId) throws -> [Mark] - - func marksAt(obj: ObjId, heads: [ChangeHash]) throws -> [Mark] - - func merge(other: Doc) throws - - func mergeWithPatches(other: Doc) throws -> [Patch] - - func objectType(obj: ObjId) -> ObjType - - func path(obj: ObjId) throws -> [PathElement] - - func putInList(obj: ObjId, index: UInt64, value: ScalarValue) throws - - func putInMap(obj: ObjId, key: String, value: ScalarValue) throws - - func putObjectInList(obj: ObjId, index: UInt64, objType: ObjType) throws -> ObjId - - func putObjectInMap(obj: ObjId, key: String, objType: ObjType) throws -> ObjId - - func receiveSyncMessage(state: SyncState, msg: [UInt8]) throws - - func receiveSyncMessageWithPatches(state: SyncState, msg: [UInt8]) throws -> [Patch] - - func save() -> [UInt8] - - func setActor(actor: ActorId) - - func splice(obj: ObjId, start: UInt64, delete: Int64, values: [ScalarValue]) throws - - func spliceText(obj: ObjId, start: UInt64, delete: Int64, chars: String) throws - - func text(obj: ObjId) throws -> String - - func textAt(obj: ObjId, heads: [ChangeHash]) throws -> String - - func updateText(obj: ObjId, chars: String) throws - - func values(obj: ObjId) throws -> [Value] - - func valuesAt(obj: ObjId, heads: [ChangeHash]) throws -> [Value] +public protocol DocProtocol : AnyObject { + + func actorId() -> ActorId + + func applyEncodedChanges(changes: [UInt8]) throws + + func applyEncodedChangesWithPatches(changes: [UInt8]) throws -> [Patch] + + func changeByHash(hash: ChangeHash) -> Change? + + func changes() -> [ChangeHash] + + func commitWith(msg: String?, time: Int64) + + func cursor(obj: ObjId, position: UInt64) throws -> Cursor + + func cursorAt(obj: ObjId, position: UInt64, heads: [ChangeHash]) throws -> Cursor + + func cursorPosition(obj: ObjId, cursor: Cursor) throws -> UInt64 + + func cursorPositionAt(obj: ObjId, cursor: Cursor, heads: [ChangeHash]) throws -> UInt64 + + func deleteInList(obj: ObjId, index: UInt64) throws + + func deleteInMap(obj: ObjId, key: String) throws + + func difference(before: [ChangeHash], after: [ChangeHash]) -> [Patch] + + func encodeChangesSince(heads: [ChangeHash]) throws -> [UInt8] + + func encodeNewChanges() -> [UInt8] + + func fork() -> Doc + + func forkAt(heads: [ChangeHash]) throws -> Doc + + func generateSyncMessage(state: SyncState) -> [UInt8]? + + func getAllAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash]) throws -> [Value] + + func getAllAtInMap(obj: ObjId, key: String, heads: [ChangeHash]) throws -> [Value] + + func getAllInList(obj: ObjId, index: UInt64) throws -> [Value] + + func getAllInMap(obj: ObjId, key: String) throws -> [Value] + + func getAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash]) throws -> Value? + + func getAtInMap(obj: ObjId, key: String, heads: [ChangeHash]) throws -> Value? + + func getInList(obj: ObjId, index: UInt64) throws -> Value? + + func getInMap(obj: ObjId, key: String) throws -> Value? + + func heads() -> [ChangeHash] + + func incrementInList(obj: ObjId, index: UInt64, by: Int64) throws + + func incrementInMap(obj: ObjId, key: String, by: Int64) throws + + func insertInList(obj: ObjId, index: UInt64, value: ScalarValue) throws + + func insertObjectInList(obj: ObjId, index: UInt64, objType: ObjType) throws -> ObjId + + func length(obj: ObjId) -> UInt64 + + func lengthAt(obj: ObjId, heads: [ChangeHash]) -> UInt64 + + func mapEntries(obj: ObjId) throws -> [KeyValue] + + func mapEntriesAt(obj: ObjId, heads: [ChangeHash]) throws -> [KeyValue] + + func mapKeys(obj: ObjId) -> [String] + + func mapKeysAt(obj: ObjId, heads: [ChangeHash]) -> [String] + + func mark(obj: ObjId, start: UInt64, end: UInt64, expand: ExpandMark, name: String, value: ScalarValue) throws + + func marks(obj: ObjId) throws -> [Mark] + + func marksAt(obj: ObjId, heads: [ChangeHash]) throws -> [Mark] + + func merge(other: Doc) throws + + func mergeWithPatches(other: Doc) throws -> [Patch] + + func objectType(obj: ObjId) -> ObjType + + func path(obj: ObjId) throws -> [PathElement] + + func putInList(obj: ObjId, index: UInt64, value: ScalarValue) throws + + func putInMap(obj: ObjId, key: String, value: ScalarValue) throws + + func putObjectInList(obj: ObjId, index: UInt64, objType: ObjType) throws -> ObjId + + func putObjectInMap(obj: ObjId, key: String, objType: ObjType) throws -> ObjId + + func receiveSyncMessage(state: SyncState, msg: [UInt8]) throws + + func receiveSyncMessageWithPatches(state: SyncState, msg: [UInt8]) throws -> [Patch] + + func save() -> [UInt8] + + func setActor(actor: ActorId) + + func splice(obj: ObjId, start: UInt64, delete: Int64, values: [ScalarValue]) throws + + func spliceText(obj: ObjId, start: UInt64, delete: Int64, chars: String) throws + + func text(obj: ObjId) throws -> String + + func textAt(obj: ObjId, heads: [ChangeHash]) throws -> String + + func updateText(obj: ObjId, chars: String) throws + + func values(obj: ObjId) throws -> [Value] + + func valuesAt(obj: ObjId, heads: [ChangeHash]) throws -> [Value] + } open class Doc: - DocProtocol -{ + DocProtocol { fileprivate let pointer: UnsafeMutableRawPointer! /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. @@ -622,34 +629,30 @@ open class Doc: // 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`. - public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that - /// may be implemented for classes extending [FFIObject]. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. /// /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there - /// isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer _: NoPointer) { - pointer = nil + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil } public func uniffiClonePointer() -> UnsafeMutableRawPointer { - try! rustCall { uniffi_uniffi_automerge_fn_clone_doc(self.pointer, $0) } - } - - public convenience init() { - let pointer = - try! rustCall { - uniffi_uniffi_automerge_fn_constructor_doc_new( - $0 - ) - } - self.init(unsafeFromRawPointer: pointer) + return try! rustCall { uniffi_uniffi_automerge_fn_clone_doc(self.pointer, $0) } } +public convenience init() { + let pointer = + try! rustCall() { + uniffi_uniffi_automerge_fn_constructor_doc_new($0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { guard let pointer = pointer else { @@ -659,664 +662,547 @@ open class Doc: try! rustCall { uniffi_uniffi_automerge_fn_free_doc(pointer, $0) } } - public static func load(bytes: [UInt8]) throws -> Doc { - try FfiConverterTypeDoc.lift(rustCallWithError(FfiConverterTypeLoadError.lift) { - uniffi_uniffi_automerge_fn_constructor_doc_load( - FfiConverterSequenceUInt8.lower(bytes), $0 - ) - }) - } - - public static func newWithActor(actor: ActorId) -> Doc { - try! FfiConverterTypeDoc.lift(try! rustCall { - uniffi_uniffi_automerge_fn_constructor_doc_new_with_actor( - FfiConverterTypeActorId.lower(actor), $0 - ) - }) - } - - open func actorId() -> ActorId { - try! FfiConverterTypeActorId.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_actor_id( - self.uniffiClonePointer(), - $0 - ) - }) - } - - open func applyEncodedChanges(changes: [UInt8]) throws { try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_apply_encoded_changes( - self.uniffiClonePointer(), - FfiConverterSequenceUInt8.lower(changes), - $0 - ) - } - } - - open func applyEncodedChangesWithPatches(changes: [UInt8]) throws -> [Patch] { - try FfiConverterSequenceTypePatch.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_apply_encoded_changes_with_patches( - self.uniffiClonePointer(), - FfiConverterSequenceUInt8.lower(changes), - $0 - ) - }) - } - - open func changeByHash(hash: ChangeHash) -> Change? { - try! FfiConverterOptionTypeChange.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_change_by_hash( - self.uniffiClonePointer(), - FfiConverterTypeChangeHash.lower(hash), - $0 - ) - }) - } - - open func changes() -> [ChangeHash] { - try! FfiConverterSequenceTypeChangeHash.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_changes( - self.uniffiClonePointer(), - $0 - ) - }) - } - - open func commitWith(msg: String?, time: Int64) { try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_commit_with( - self.uniffiClonePointer(), - FfiConverterOptionString.lower(msg), - FfiConverterInt64.lower(time), - $0 - ) - } - } - - open func cursor(obj: ObjId, position: UInt64) throws -> Cursor { - try FfiConverterTypeCursor.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_cursor( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(position), - $0 - ) - }) - } - - open func cursorAt(obj: ObjId, position: UInt64, heads: [ChangeHash]) throws -> Cursor { - try FfiConverterTypeCursor.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_cursor_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(position), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func cursorPosition(obj: ObjId, cursor: Cursor) throws -> UInt64 { - try FfiConverterUInt64.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_cursor_position( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterTypeCursor.lower(cursor), - $0 - ) - }) - } - - open func cursorPositionAt(obj: ObjId, cursor: Cursor, heads: [ChangeHash]) throws -> UInt64 { - try FfiConverterUInt64.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_cursor_position_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterTypeCursor.lower(cursor), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func deleteInList(obj: ObjId, index: UInt64) throws { try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_delete_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - $0 - ) - } - } - - open func deleteInMap(obj: ObjId, key: String) throws { try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_delete_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - $0 - ) - } - } - - open func encodeChangesSince(heads: [ChangeHash]) throws -> [UInt8] { - try FfiConverterSequenceUInt8.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_encode_changes_since( - self.uniffiClonePointer(), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func encodeNewChanges() -> [UInt8] { - try! FfiConverterSequenceUInt8.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_encode_new_changes( - self.uniffiClonePointer(), - $0 - ) - }) - } - - open func fork() -> Doc { - try! FfiConverterTypeDoc.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_fork( - self.uniffiClonePointer(), - $0 - ) - }) - } - - open func forkAt(heads: [ChangeHash]) throws -> Doc { - try FfiConverterTypeDoc.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_fork_at( - self.uniffiClonePointer(), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func generateSyncMessage(state: SyncState) -> [UInt8]? { - try! FfiConverterOptionSequenceUInt8.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_generate_sync_message( - self.uniffiClonePointer(), - FfiConverterTypeSyncState.lower(state), - $0 - ) - }) - } - - open func getAllAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash]) throws -> [Value] { - try FfiConverterSequenceTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_all_at_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func getAllAtInMap(obj: ObjId, key: String, heads: [ChangeHash]) throws -> [Value] { - try FfiConverterSequenceTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_all_at_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func getAllInList(obj: ObjId, index: UInt64) throws -> [Value] { - try FfiConverterSequenceTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_all_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - $0 - ) - }) - } - - open func getAllInMap(obj: ObjId, key: String) throws -> [Value] { - try FfiConverterSequenceTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_all_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - $0 - ) - }) - } - - open func getAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash]) throws -> Value? { - try FfiConverterOptionTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_at_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func getAtInMap(obj: ObjId, key: String, heads: [ChangeHash]) throws -> Value? { - try FfiConverterOptionTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_at_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func getInList(obj: ObjId, index: UInt64) throws -> Value? { - try FfiConverterOptionTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - $0 - ) - }) - } - - open func getInMap(obj: ObjId, key: String) throws -> Value? { - try FfiConverterOptionTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_get_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - $0 - ) - }) - } - - open func heads() -> [ChangeHash] { - try! FfiConverterSequenceTypeChangeHash.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_heads( - self.uniffiClonePointer(), - $0 - ) - }) - } - - open func incrementInList(obj: ObjId, index: UInt64, by: Int64) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_increment_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - FfiConverterInt64.lower(by), - $0 - ) - } - } - - open func incrementInMap(obj: ObjId, key: String, by: Int64) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_increment_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - FfiConverterInt64.lower(by), - $0 - ) - } - } - - open func insertInList(obj: ObjId, index: UInt64, value: ScalarValue) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_insert_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - FfiConverterTypeScalarValue.lower(value), - $0 - ) - } - } - - open func insertObjectInList(obj: ObjId, index: UInt64, objType: ObjType) throws -> ObjId { - try FfiConverterTypeObjId.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_insert_object_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - FfiConverterTypeObjType.lower(objType), - $0 - ) - }) - } - - open func length(obj: ObjId) -> UInt64 { - try! FfiConverterUInt64.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_length( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } - - open func lengthAt(obj: ObjId, heads: [ChangeHash]) -> UInt64 { - try! FfiConverterUInt64.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_length_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func mapEntries(obj: ObjId) throws -> [KeyValue] { - try FfiConverterSequenceTypeKeyValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_map_entries( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } - - open func mapEntriesAt(obj: ObjId, heads: [ChangeHash]) throws -> [KeyValue] { - try FfiConverterSequenceTypeKeyValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_map_entries_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func mapKeys(obj: ObjId) -> [String] { - try! FfiConverterSequenceString.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_map_keys( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } - - open func mapKeysAt(obj: ObjId, heads: [ChangeHash]) -> [String] { - try! FfiConverterSequenceString.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_map_keys_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func mark( - obj: ObjId, - start: UInt64, - end: UInt64, - expand: ExpandMark, - name: String, - value: ScalarValue - ) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_mark( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(start), - FfiConverterUInt64.lower(end), - FfiConverterTypeExpandMark.lower(expand), - FfiConverterString.lower(name), - FfiConverterTypeScalarValue.lower(value), - $0 - ) - } - } - - open func marks(obj: ObjId) throws -> [Mark] { - try FfiConverterSequenceTypeMark.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_marks( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } - - open func marksAt(obj: ObjId, heads: [ChangeHash]) throws -> [Mark] { - try FfiConverterSequenceTypeMark.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_marks_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func merge(other: Doc) throws { try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_merge( - self.uniffiClonePointer(), - FfiConverterTypeDoc.lower(other), - $0 - ) - } - } - - open func mergeWithPatches(other: Doc) throws -> [Patch] { - try FfiConverterSequenceTypePatch.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_merge_with_patches( - self.uniffiClonePointer(), - FfiConverterTypeDoc.lower(other), - $0 - ) - }) - } - - open func objectType(obj: ObjId) -> ObjType { - try! FfiConverterTypeObjType.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_object_type( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } - - open func path(obj: ObjId) throws -> [PathElement] { - try FfiConverterSequenceTypePathElement.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_path( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } - - open func putInList(obj: ObjId, index: UInt64, value: ScalarValue) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_put_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - FfiConverterTypeScalarValue.lower(value), - $0 - ) - } - } - - open func putInMap(obj: ObjId, key: String, value: ScalarValue) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_put_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - FfiConverterTypeScalarValue.lower(value), - $0 - ) - } - } - - open func putObjectInList(obj: ObjId, index: UInt64, objType: ObjType) throws -> ObjId { - try FfiConverterTypeObjId.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_put_object_in_list( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(index), - FfiConverterTypeObjType.lower(objType), - $0 - ) - }) - } - - open func putObjectInMap(obj: ObjId, key: String, objType: ObjType) throws -> ObjId { - try FfiConverterTypeObjId.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_put_object_in_map( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(key), - FfiConverterTypeObjType.lower(objType), - $0 - ) - }) - } - - open func receiveSyncMessage(state: SyncState, msg: [UInt8]) throws { - try rustCallWithError(FfiConverterTypeReceiveSyncError.lift) { - uniffi_uniffi_automerge_fn_method_doc_receive_sync_message( - self.uniffiClonePointer(), - FfiConverterTypeSyncState.lower(state), - FfiConverterSequenceUInt8.lower(msg), - $0 - ) - } - } - - open func receiveSyncMessageWithPatches(state: SyncState, msg: [UInt8]) throws -> [Patch] { - try FfiConverterSequenceTypePatch.lift(rustCallWithError(FfiConverterTypeReceiveSyncError.lift) { - uniffi_uniffi_automerge_fn_method_doc_receive_sync_message_with_patches( - self.uniffiClonePointer(), - FfiConverterTypeSyncState.lower(state), - FfiConverterSequenceUInt8.lower(msg), - $0 - ) - }) - } - - open func save() -> [UInt8] { - try! FfiConverterSequenceUInt8.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_save( - self.uniffiClonePointer(), - $0 - ) - }) - } - - open func setActor(actor: ActorId) { try! rustCall { - uniffi_uniffi_automerge_fn_method_doc_set_actor( - self.uniffiClonePointer(), - FfiConverterTypeActorId.lower(actor), - $0 - ) - } - } - - open func splice(obj: ObjId, start: UInt64, delete: Int64, values: [ScalarValue]) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_splice( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(start), - FfiConverterInt64.lower(delete), - FfiConverterSequenceTypeScalarValue.lower(values), - $0 - ) - } - } - - open func spliceText(obj: ObjId, start: UInt64, delete: Int64, chars: String) throws { - try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_splice_text( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt64.lower(start), - FfiConverterInt64.lower(delete), - FfiConverterString.lower(chars), - $0 - ) - } - } - - open func text(obj: ObjId) throws -> String { - try FfiConverterString.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_text( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } - - open func textAt(obj: ObjId, heads: [ChangeHash]) throws -> String { - try FfiConverterString.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_text_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } - - open func updateText(obj: ObjId, chars: String) throws { try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_update_text( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterString.lower(chars), - $0 - ) - } - } + +public static func load(bytes: [UInt8])throws -> Doc { + return try FfiConverterTypeDoc.lift(try rustCallWithError(FfiConverterTypeLoadError.lift) { + uniffi_uniffi_automerge_fn_constructor_doc_load( + FfiConverterSequenceUInt8.lower(bytes),$0 + ) +}) +} + +public static func newWithActor(actor: ActorId) -> Doc { + return try! FfiConverterTypeDoc.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_constructor_doc_new_with_actor( + FfiConverterTypeActorId.lower(actor),$0 + ) +}) +} + - open func values(obj: ObjId) throws -> [Value] { - try FfiConverterSequenceTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_values( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - $0 - ) - }) - } + +open func actorId() -> ActorId { + return try! FfiConverterTypeActorId.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_actor_id(self.uniffiClonePointer(),$0 + ) +}) +} + +open func applyEncodedChanges(changes: [UInt8])throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_apply_encoded_changes(self.uniffiClonePointer(), + FfiConverterSequenceUInt8.lower(changes),$0 + ) +} +} + +open func applyEncodedChangesWithPatches(changes: [UInt8])throws -> [Patch] { + return try FfiConverterSequenceTypePatch.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_apply_encoded_changes_with_patches(self.uniffiClonePointer(), + FfiConverterSequenceUInt8.lower(changes),$0 + ) +}) +} + +open func changeByHash(hash: ChangeHash) -> Change? { + return try! FfiConverterOptionTypeChange.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_change_by_hash(self.uniffiClonePointer(), + FfiConverterTypeChangeHash.lower(hash),$0 + ) +}) +} + +open func changes() -> [ChangeHash] { + return try! FfiConverterSequenceTypeChangeHash.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_changes(self.uniffiClonePointer(),$0 + ) +}) +} + +open func commitWith(msg: String?, time: Int64) {try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_commit_with(self.uniffiClonePointer(), + FfiConverterOptionString.lower(msg), + FfiConverterInt64.lower(time),$0 + ) +} +} + +open func cursor(obj: ObjId, position: UInt64)throws -> Cursor { + return try FfiConverterTypeCursor.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_cursor(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(position),$0 + ) +}) +} + +open func cursorAt(obj: ObjId, position: UInt64, heads: [ChangeHash])throws -> Cursor { + return try FfiConverterTypeCursor.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_cursor_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(position), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func cursorPosition(obj: ObjId, cursor: Cursor)throws -> UInt64 { + return try FfiConverterUInt64.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_cursor_position(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterTypeCursor.lower(cursor),$0 + ) +}) +} + +open func cursorPositionAt(obj: ObjId, cursor: Cursor, heads: [ChangeHash])throws -> UInt64 { + return try FfiConverterUInt64.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_cursor_position_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterTypeCursor.lower(cursor), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func deleteInList(obj: ObjId, index: UInt64)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_delete_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index),$0 + ) +} +} + +open func deleteInMap(obj: ObjId, key: String)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_delete_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key),$0 + ) +} +} + +open func difference(before: [ChangeHash], after: [ChangeHash]) -> [Patch] { + return try! FfiConverterSequenceTypePatch.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_difference(self.uniffiClonePointer(), + FfiConverterSequenceTypeChangeHash.lower(before), + FfiConverterSequenceTypeChangeHash.lower(after),$0 + ) +}) +} + +open func encodeChangesSince(heads: [ChangeHash])throws -> [UInt8] { + return try FfiConverterSequenceUInt8.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_encode_changes_since(self.uniffiClonePointer(), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func encodeNewChanges() -> [UInt8] { + return try! FfiConverterSequenceUInt8.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_encode_new_changes(self.uniffiClonePointer(),$0 + ) +}) +} + +open func fork() -> Doc { + return try! FfiConverterTypeDoc.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_fork(self.uniffiClonePointer(),$0 + ) +}) +} + +open func forkAt(heads: [ChangeHash])throws -> Doc { + return try FfiConverterTypeDoc.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_fork_at(self.uniffiClonePointer(), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func generateSyncMessage(state: SyncState) -> [UInt8]? { + return try! FfiConverterOptionSequenceUInt8.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_generate_sync_message(self.uniffiClonePointer(), + FfiConverterTypeSyncState.lower(state),$0 + ) +}) +} + +open func getAllAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash])throws -> [Value] { + return try FfiConverterSequenceTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_all_at_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func getAllAtInMap(obj: ObjId, key: String, heads: [ChangeHash])throws -> [Value] { + return try FfiConverterSequenceTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_all_at_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func getAllInList(obj: ObjId, index: UInt64)throws -> [Value] { + return try FfiConverterSequenceTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_all_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index),$0 + ) +}) +} + +open func getAllInMap(obj: ObjId, key: String)throws -> [Value] { + return try FfiConverterSequenceTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_all_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key),$0 + ) +}) +} + +open func getAtInList(obj: ObjId, index: UInt64, heads: [ChangeHash])throws -> Value? { + return try FfiConverterOptionTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_at_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func getAtInMap(obj: ObjId, key: String, heads: [ChangeHash])throws -> Value? { + return try FfiConverterOptionTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_at_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func getInList(obj: ObjId, index: UInt64)throws -> Value? { + return try FfiConverterOptionTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index),$0 + ) +}) +} + +open func getInMap(obj: ObjId, key: String)throws -> Value? { + return try FfiConverterOptionTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_get_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key),$0 + ) +}) +} + +open func heads() -> [ChangeHash] { + return try! FfiConverterSequenceTypeChangeHash.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_heads(self.uniffiClonePointer(),$0 + ) +}) +} + +open func incrementInList(obj: ObjId, index: UInt64, by: Int64)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_increment_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index), + FfiConverterInt64.lower(by),$0 + ) +} +} + +open func incrementInMap(obj: ObjId, key: String, by: Int64)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_increment_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key), + FfiConverterInt64.lower(by),$0 + ) +} +} + +open func insertInList(obj: ObjId, index: UInt64, value: ScalarValue)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_insert_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index), + FfiConverterTypeScalarValue.lower(value),$0 + ) +} +} + +open func insertObjectInList(obj: ObjId, index: UInt64, objType: ObjType)throws -> ObjId { + return try FfiConverterTypeObjId.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_insert_object_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index), + FfiConverterTypeObjType.lower(objType),$0 + ) +}) +} + +open func length(obj: ObjId) -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_length(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func lengthAt(obj: ObjId, heads: [ChangeHash]) -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_length_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func mapEntries(obj: ObjId)throws -> [KeyValue] { + return try FfiConverterSequenceTypeKeyValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_map_entries(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func mapEntriesAt(obj: ObjId, heads: [ChangeHash])throws -> [KeyValue] { + return try FfiConverterSequenceTypeKeyValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_map_entries_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func mapKeys(obj: ObjId) -> [String] { + return try! FfiConverterSequenceString.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_map_keys(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func mapKeysAt(obj: ObjId, heads: [ChangeHash]) -> [String] { + return try! FfiConverterSequenceString.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_map_keys_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func mark(obj: ObjId, start: UInt64, end: UInt64, expand: ExpandMark, name: String, value: ScalarValue)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_mark(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(start), + FfiConverterUInt64.lower(end), + FfiConverterTypeExpandMark.lower(expand), + FfiConverterString.lower(name), + FfiConverterTypeScalarValue.lower(value),$0 + ) +} +} + +open func marks(obj: ObjId)throws -> [Mark] { + return try FfiConverterSequenceTypeMark.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_marks(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func marksAt(obj: ObjId, heads: [ChangeHash])throws -> [Mark] { + return try FfiConverterSequenceTypeMark.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_marks_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func merge(other: Doc)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_merge(self.uniffiClonePointer(), + FfiConverterTypeDoc.lower(other),$0 + ) +} +} + +open func mergeWithPatches(other: Doc)throws -> [Patch] { + return try FfiConverterSequenceTypePatch.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_merge_with_patches(self.uniffiClonePointer(), + FfiConverterTypeDoc.lower(other),$0 + ) +}) +} + +open func objectType(obj: ObjId) -> ObjType { + return try! FfiConverterTypeObjType.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_object_type(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func path(obj: ObjId)throws -> [PathElement] { + return try FfiConverterSequenceTypePathElement.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_path(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func putInList(obj: ObjId, index: UInt64, value: ScalarValue)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_put_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index), + FfiConverterTypeScalarValue.lower(value),$0 + ) +} +} + +open func putInMap(obj: ObjId, key: String, value: ScalarValue)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_put_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key), + FfiConverterTypeScalarValue.lower(value),$0 + ) +} +} + +open func putObjectInList(obj: ObjId, index: UInt64, objType: ObjType)throws -> ObjId { + return try FfiConverterTypeObjId.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_put_object_in_list(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(index), + FfiConverterTypeObjType.lower(objType),$0 + ) +}) +} + +open func putObjectInMap(obj: ObjId, key: String, objType: ObjType)throws -> ObjId { + return try FfiConverterTypeObjId.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_put_object_in_map(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(key), + FfiConverterTypeObjType.lower(objType),$0 + ) +}) +} + +open func receiveSyncMessage(state: SyncState, msg: [UInt8])throws {try rustCallWithError(FfiConverterTypeReceiveSyncError.lift) { + uniffi_uniffi_automerge_fn_method_doc_receive_sync_message(self.uniffiClonePointer(), + FfiConverterTypeSyncState.lower(state), + FfiConverterSequenceUInt8.lower(msg),$0 + ) +} +} + +open func receiveSyncMessageWithPatches(state: SyncState, msg: [UInt8])throws -> [Patch] { + return try FfiConverterSequenceTypePatch.lift(try rustCallWithError(FfiConverterTypeReceiveSyncError.lift) { + uniffi_uniffi_automerge_fn_method_doc_receive_sync_message_with_patches(self.uniffiClonePointer(), + FfiConverterTypeSyncState.lower(state), + FfiConverterSequenceUInt8.lower(msg),$0 + ) +}) +} + +open func save() -> [UInt8] { + return try! FfiConverterSequenceUInt8.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_save(self.uniffiClonePointer(),$0 + ) +}) +} + +open func setActor(actor: ActorId) {try! rustCall() { + uniffi_uniffi_automerge_fn_method_doc_set_actor(self.uniffiClonePointer(), + FfiConverterTypeActorId.lower(actor),$0 + ) +} +} + +open func splice(obj: ObjId, start: UInt64, delete: Int64, values: [ScalarValue])throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_splice(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(start), + FfiConverterInt64.lower(delete), + FfiConverterSequenceTypeScalarValue.lower(values),$0 + ) +} +} + +open func spliceText(obj: ObjId, start: UInt64, delete: Int64, chars: String)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_splice_text(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt64.lower(start), + FfiConverterInt64.lower(delete), + FfiConverterString.lower(chars),$0 + ) +} +} + +open func text(obj: ObjId)throws -> String { + return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_text(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func textAt(obj: ObjId, heads: [ChangeHash])throws -> String { + return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_text_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + +open func updateText(obj: ObjId, chars: String)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_update_text(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterString.lower(chars),$0 + ) +} +} + +open func values(obj: ObjId)throws -> [Value] { + return try FfiConverterSequenceTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_values(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj),$0 + ) +}) +} + +open func valuesAt(obj: ObjId, heads: [ChangeHash])throws -> [Value] { + return try FfiConverterSequenceTypeValue.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_values_at(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterSequenceTypeChangeHash.lower(heads),$0 + ) +}) +} + - open func valuesAt(obj: ObjId, heads: [ChangeHash]) throws -> [Value] { - try FfiConverterSequenceTypeValue.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_values_at( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterSequenceTypeChangeHash.lower(heads), - $0 - ) - }) - } } public struct FfiConverterTypeDoc: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = Doc public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Doc { - Doc(unsafeFromRawPointer: pointer) + return Doc(unsafeFromRawPointer: pointer) } public static func lower(_ value: Doc) -> UnsafeMutableRawPointer { - value.uniffiClonePointer() + return value.uniffiClonePointer() } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Doc { @@ -1324,7 +1210,7 @@ public struct FfiConverterTypeDoc: FfiConverter { // 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 { + if (ptr == nil) { throw UniffiInternalError.unexpectedNullPointer } return try lift(ptr!) @@ -1337,25 +1223,32 @@ public struct FfiConverterTypeDoc: FfiConverter { } } + + + public func FfiConverterTypeDoc_lift(_ pointer: UnsafeMutableRawPointer) throws -> Doc { - try FfiConverterTypeDoc.lift(pointer) + return try FfiConverterTypeDoc.lift(pointer) } public func FfiConverterTypeDoc_lower(_ value: Doc) -> UnsafeMutableRawPointer { - FfiConverterTypeDoc.lower(value) + return FfiConverterTypeDoc.lower(value) } -public protocol SyncStateProtocol: AnyObject { - func encode() -> [UInt8] - func reset() - func theirHeads() -> [ChangeHash]? + +public protocol SyncStateProtocol : AnyObject { + + func encode() -> [UInt8] + + func reset() + + func theirHeads() -> [ChangeHash]? + } open class SyncState: - SyncStateProtocol -{ + SyncStateProtocol { fileprivate let pointer: UnsafeMutableRawPointer! /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. @@ -1366,34 +1259,30 @@ open class SyncState: // 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`. - public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that - /// may be implemented for classes extending [FFIObject]. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. /// /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there - /// isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer _: NoPointer) { - pointer = nil + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil } public func uniffiClonePointer() -> UnsafeMutableRawPointer { - try! rustCall { uniffi_uniffi_automerge_fn_clone_syncstate(self.pointer, $0) } - } - - public convenience init() { - let pointer = - try! rustCall { - uniffi_uniffi_automerge_fn_constructor_syncstate_new( - $0 - ) - } - self.init(unsafeFromRawPointer: pointer) + return try! rustCall { uniffi_uniffi_automerge_fn_clone_syncstate(self.pointer, $0) } } +public convenience init() { + let pointer = + try! rustCall() { + uniffi_uniffi_automerge_fn_constructor_syncstate_new($0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { guard let pointer = pointer else { @@ -1403,51 +1292,51 @@ open class SyncState: try! rustCall { uniffi_uniffi_automerge_fn_free_syncstate(pointer, $0) } } - public static func decode(bytes: [UInt8]) throws -> SyncState { - try FfiConverterTypeSyncState.lift(rustCallWithError(FfiConverterTypeDecodeSyncStateError.lift) { - uniffi_uniffi_automerge_fn_constructor_syncstate_decode( - FfiConverterSequenceUInt8.lower(bytes), $0 - ) - }) - } - - open func encode() -> [UInt8] { - try! FfiConverterSequenceUInt8.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_syncstate_encode( - self.uniffiClonePointer(), - $0 - ) - }) - } + +public static func decode(bytes: [UInt8])throws -> SyncState { + return try FfiConverterTypeSyncState.lift(try rustCallWithError(FfiConverterTypeDecodeSyncStateError.lift) { + uniffi_uniffi_automerge_fn_constructor_syncstate_decode( + FfiConverterSequenceUInt8.lower(bytes),$0 + ) +}) +} + - open func reset() { try! rustCall { - uniffi_uniffi_automerge_fn_method_syncstate_reset( - self.uniffiClonePointer(), - $0 - ) - } - } + +open func encode() -> [UInt8] { + return try! FfiConverterSequenceUInt8.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_syncstate_encode(self.uniffiClonePointer(),$0 + ) +}) +} + +open func reset() {try! rustCall() { + uniffi_uniffi_automerge_fn_method_syncstate_reset(self.uniffiClonePointer(),$0 + ) +} +} + +open func theirHeads() -> [ChangeHash]? { + return try! FfiConverterOptionSequenceTypeChangeHash.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_method_syncstate_their_heads(self.uniffiClonePointer(),$0 + ) +}) +} + - open func theirHeads() -> [ChangeHash]? { - try! FfiConverterOptionSequenceTypeChangeHash.lift(try! rustCall { - uniffi_uniffi_automerge_fn_method_syncstate_their_heads( - self.uniffiClonePointer(), - $0 - ) - }) - } } public struct FfiConverterTypeSyncState: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = SyncState public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncState { - SyncState(unsafeFromRawPointer: pointer) + return SyncState(unsafeFromRawPointer: pointer) } public static func lower(_ value: SyncState) -> UnsafeMutableRawPointer { - value.uniffiClonePointer() + return value.uniffiClonePointer() } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SyncState { @@ -1455,7 +1344,7 @@ public struct FfiConverterTypeSyncState: FfiConverter { // 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 { + if (ptr == nil) { throw UniffiInternalError.unexpectedNullPointer } return try lift(ptr!) @@ -1468,14 +1357,18 @@ public struct FfiConverterTypeSyncState: FfiConverter { } } + + + public func FfiConverterTypeSyncState_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncState { - try FfiConverterTypeSyncState.lift(pointer) + return try FfiConverterTypeSyncState.lift(pointer) } public func FfiConverterTypeSyncState_lower(_ value: SyncState) -> UnsafeMutableRawPointer { - FfiConverterTypeSyncState.lower(value) + return FfiConverterTypeSyncState.lower(value) } + public struct Change { public var actorId: ActorId public var message: String? @@ -1486,14 +1379,7 @@ public struct Change { // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - actorId: ActorId, - message: String?, - deps: [ChangeHash], - timestamp: Int64, - bytes: [UInt8], - hash: ChangeHash - ) { + public init(actorId: ActorId, message: String?, deps: [ChangeHash], timestamp: Int64, bytes: [UInt8], hash: ChangeHash) { self.actorId = actorId self.message = message self.deps = deps @@ -1503,8 +1389,10 @@ public struct Change { } } + + extension Change: Equatable, Hashable { - public static func == (lhs: Change, rhs: Change) -> Bool { + public static func ==(lhs: Change, rhs: Change) -> Bool { if lhs.actorId != rhs.actorId { return false } @@ -1536,15 +1424,17 @@ extension Change: Equatable, Hashable { } } + public struct FfiConverterTypeChange: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Change { - try Change( - actorId: FfiConverterTypeActorId.read(from: &buf), - message: FfiConverterOptionString.read(from: &buf), - deps: FfiConverterSequenceTypeChangeHash.read(from: &buf), - timestamp: FfiConverterInt64.read(from: &buf), - bytes: FfiConverterSequenceUInt8.read(from: &buf), - hash: FfiConverterTypeChangeHash.read(from: &buf) + return + try Change( + actorId: FfiConverterTypeActorId.read(from: &buf), + message: FfiConverterOptionString.read(from: &buf), + deps: FfiConverterSequenceTypeChangeHash.read(from: &buf), + timestamp: FfiConverterInt64.read(from: &buf), + bytes: FfiConverterSequenceUInt8.read(from: &buf), + hash: FfiConverterTypeChangeHash.read(from: &buf) ) } @@ -1558,14 +1448,16 @@ public struct FfiConverterTypeChange: FfiConverterRustBuffer { } } + public func FfiConverterTypeChange_lift(_ buf: RustBuffer) throws -> Change { - try FfiConverterTypeChange.lift(buf) + return try FfiConverterTypeChange.lift(buf) } public func FfiConverterTypeChange_lower(_ value: Change) -> RustBuffer { - FfiConverterTypeChange.lower(value) + return FfiConverterTypeChange.lower(value) } + public struct KeyValue { public var key: String public var value: Value @@ -1578,8 +1470,10 @@ public struct KeyValue { } } + + extension KeyValue: Equatable, Hashable { - public static func == (lhs: KeyValue, rhs: KeyValue) -> Bool { + public static func ==(lhs: KeyValue, rhs: KeyValue) -> Bool { if lhs.key != rhs.key { return false } @@ -1595,11 +1489,13 @@ extension KeyValue: Equatable, Hashable { } } + public struct FfiConverterTypeKeyValue: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyValue { - try KeyValue( - key: FfiConverterString.read(from: &buf), - value: FfiConverterTypeValue.read(from: &buf) + return + try KeyValue( + key: FfiConverterString.read(from: &buf), + value: FfiConverterTypeValue.read(from: &buf) ) } @@ -1609,14 +1505,16 @@ public struct FfiConverterTypeKeyValue: FfiConverterRustBuffer { } } + public func FfiConverterTypeKeyValue_lift(_ buf: RustBuffer) throws -> KeyValue { - try FfiConverterTypeKeyValue.lift(buf) + return try FfiConverterTypeKeyValue.lift(buf) } public func FfiConverterTypeKeyValue_lower(_ value: KeyValue) -> RustBuffer { - FfiConverterTypeKeyValue.lower(value) + return FfiConverterTypeKeyValue.lower(value) } + public struct Mark { public var start: UInt64 public var end: UInt64 @@ -1633,8 +1531,10 @@ public struct Mark { } } + + extension Mark: Equatable, Hashable { - public static func == (lhs: Mark, rhs: Mark) -> Bool { + public static func ==(lhs: Mark, rhs: Mark) -> Bool { if lhs.start != rhs.start { return false } @@ -1658,13 +1558,15 @@ extension Mark: Equatable, Hashable { } } + public struct FfiConverterTypeMark: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Mark { - try Mark( - start: FfiConverterUInt64.read(from: &buf), - end: FfiConverterUInt64.read(from: &buf), - name: FfiConverterString.read(from: &buf), - value: FfiConverterTypeValue.read(from: &buf) + return + try Mark( + start: FfiConverterUInt64.read(from: &buf), + end: FfiConverterUInt64.read(from: &buf), + name: FfiConverterString.read(from: &buf), + value: FfiConverterTypeValue.read(from: &buf) ) } @@ -1676,14 +1578,16 @@ public struct FfiConverterTypeMark: FfiConverterRustBuffer { } } + public func FfiConverterTypeMark_lift(_ buf: RustBuffer) throws -> Mark { - try FfiConverterTypeMark.lift(buf) + return try FfiConverterTypeMark.lift(buf) } public func FfiConverterTypeMark_lower(_ value: Mark) -> RustBuffer { - FfiConverterTypeMark.lower(value) + return FfiConverterTypeMark.lower(value) } + public struct Patch { public var path: [PathElement] public var action: PatchAction @@ -1696,8 +1600,10 @@ public struct Patch { } } + + extension Patch: Equatable, Hashable { - public static func == (lhs: Patch, rhs: Patch) -> Bool { + public static func ==(lhs: Patch, rhs: Patch) -> Bool { if lhs.path != rhs.path { return false } @@ -1713,11 +1619,13 @@ extension Patch: Equatable, Hashable { } } + public struct FfiConverterTypePatch: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Patch { - try Patch( - path: FfiConverterSequenceTypePathElement.read(from: &buf), - action: FfiConverterTypePatchAction.read(from: &buf) + return + try Patch( + path: FfiConverterSequenceTypePathElement.read(from: &buf), + action: FfiConverterTypePatchAction.read(from: &buf) ) } @@ -1727,14 +1635,16 @@ public struct FfiConverterTypePatch: FfiConverterRustBuffer { } } + public func FfiConverterTypePatch_lift(_ buf: RustBuffer) throws -> Patch { - try FfiConverterTypePatch.lift(buf) + return try FfiConverterTypePatch.lift(buf) } public func FfiConverterTypePatch_lower(_ value: Patch) -> RustBuffer { - FfiConverterTypePatch.lower(value) + return FfiConverterTypePatch.lower(value) } + public struct PathElement { public var prop: Prop public var obj: ObjId @@ -1747,8 +1657,10 @@ public struct PathElement { } } + + extension PathElement: Equatable, Hashable { - public static func == (lhs: PathElement, rhs: PathElement) -> Bool { + public static func ==(lhs: PathElement, rhs: PathElement) -> Bool { if lhs.prop != rhs.prop { return false } @@ -1764,11 +1676,13 @@ extension PathElement: Equatable, Hashable { } } + public struct FfiConverterTypePathElement: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PathElement { - try PathElement( - prop: FfiConverterTypeProp.read(from: &buf), - obj: FfiConverterTypeObjId.read(from: &buf) + return + try PathElement( + prop: FfiConverterTypeProp.read(from: &buf), + obj: FfiConverterTypeObjId.read(from: &buf) ) } @@ -1778,27 +1692,39 @@ public struct FfiConverterTypePathElement: FfiConverterRustBuffer { } } + public func FfiConverterTypePathElement_lift(_ buf: RustBuffer) throws -> PathElement { - try FfiConverterTypePathElement.lift(buf) + return try FfiConverterTypePathElement.lift(buf) } public func FfiConverterTypePathElement_lower(_ value: PathElement) -> RustBuffer { - FfiConverterTypePathElement.lower(value) + return FfiConverterTypePathElement.lower(value) } + public enum DecodeSyncStateError { + + + case Internal(message: String) + } + public struct FfiConverterTypeDecodeSyncStateError: FfiConverterRustBuffer { typealias SwiftType = DecodeSyncStateError public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DecodeSyncStateError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .Internal( - message: FfiConverterString.read(from: &buf) - ) + + + + + case 1: return .Internal( + message: try FfiConverterString.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } @@ -1806,35 +1732,53 @@ public struct FfiConverterTypeDecodeSyncStateError: FfiConverterRustBuffer { public static func write(_ value: DecodeSyncStateError, into buf: inout [UInt8]) { switch value { - case .Internal(_ /* message is ignored*/ ): + + + + + case .Internal(_ /* message is ignored*/): writeInt(&buf, Int32(1)) + + } } } + extension DecodeSyncStateError: Equatable, Hashable {} -extension DecodeSyncStateError: Error {} +extension DecodeSyncStateError: Error { } + public enum DocError { - case WrongObjectType(message: String) + + + case WrongObjectType(message: String) + case Internal(message: String) + } + public struct FfiConverterTypeDocError: FfiConverterRustBuffer { typealias SwiftType = DocError public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DocError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .WrongObjectType( - message: FfiConverterString.read(from: &buf) - ) - case 2: return try .Internal( - message: FfiConverterString.read(from: &buf) - ) + + + + case 1: return .WrongObjectType( + message: try FfiConverterString.read(from: &buf) + ) + + case 2: return .Internal( + message: try FfiConverterString.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } @@ -1842,86 +1786,118 @@ public struct FfiConverterTypeDocError: FfiConverterRustBuffer { public static func write(_ value: DocError, into buf: inout [UInt8]) { switch value { - case .WrongObjectType(_ /* message is ignored*/ ): + + + + + case .WrongObjectType(_ /* message is ignored*/): writeInt(&buf, Int32(1)) - case .Internal(_ /* message is ignored*/ ): + case .Internal(_ /* message is ignored*/): writeInt(&buf, Int32(2)) + + } } } + extension DocError: Equatable, Hashable {} -extension DocError: Error {} +extension DocError: Error { } // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum ExpandMark { + case before case after case none case both } + public struct FfiConverterTypeExpandMark: FfiConverterRustBuffer { typealias SwiftType = ExpandMark public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ExpandMark { let variant: Int32 = try readInt(&buf) switch variant { + case 1: return .before - + case 2: return .after - + case 3: return .none - + case 4: return .both - + default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: ExpandMark, into buf: inout [UInt8]) { switch value { + + case .before: writeInt(&buf, Int32(1)) - + + case .after: writeInt(&buf, Int32(2)) - + + case .none: writeInt(&buf, Int32(3)) - + + case .both: writeInt(&buf, Int32(4)) + } } } + public func FfiConverterTypeExpandMark_lift(_ buf: RustBuffer) throws -> ExpandMark { - try FfiConverterTypeExpandMark.lift(buf) + return try FfiConverterTypeExpandMark.lift(buf) } public func FfiConverterTypeExpandMark_lower(_ value: ExpandMark) -> RustBuffer { - FfiConverterTypeExpandMark.lower(value) + return FfiConverterTypeExpandMark.lower(value) } + + extension ExpandMark: Equatable, Hashable {} + + + public enum LoadError { + + + case Internal(message: String) + } + public struct FfiConverterTypeLoadError: FfiConverterRustBuffer { typealias SwiftType = LoadError public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LoadError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .Internal( - message: FfiConverterString.read(from: &buf) - ) + + + + + case 1: return .Internal( + message: try FfiConverterString.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } @@ -1929,298 +1905,311 @@ public struct FfiConverterTypeLoadError: FfiConverterRustBuffer { public static func write(_ value: LoadError, into buf: inout [UInt8]) { switch value { - case .Internal(_ /* message is ignored*/ ): + + + + + case .Internal(_ /* message is ignored*/): writeInt(&buf, Int32(1)) + + } } } + extension LoadError: Equatable, Hashable {} -extension LoadError: Error {} +extension LoadError: Error { } // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum ObjType { + case map case list case text } + public struct FfiConverterTypeObjType: FfiConverterRustBuffer { typealias SwiftType = ObjType public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ObjType { let variant: Int32 = try readInt(&buf) switch variant { + case 1: return .map - + case 2: return .list - + case 3: return .text - + default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: ObjType, into buf: inout [UInt8]) { switch value { + + case .map: writeInt(&buf, Int32(1)) - + + case .list: writeInt(&buf, Int32(2)) - + + case .text: writeInt(&buf, Int32(3)) + } } } + public func FfiConverterTypeObjType_lift(_ buf: RustBuffer) throws -> ObjType { - try FfiConverterTypeObjType.lift(buf) + return try FfiConverterTypeObjType.lift(buf) } public func FfiConverterTypeObjType_lower(_ value: ObjType) -> RustBuffer { - FfiConverterTypeObjType.lower(value) + return FfiConverterTypeObjType.lower(value) } + + extension ObjType: Equatable, Hashable {} + + // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum PatchAction { - case put( - obj: ObjId, - prop: Prop, - value: Value + + case put(obj: ObjId, prop: Prop, value: Value ) - case insert( - obj: ObjId, - index: UInt64, - values: [Value] + case insert(obj: ObjId, index: UInt64, values: [Value] ) - case spliceText( - obj: ObjId, - index: UInt64, - value: String, - marks: [String: Value] + case spliceText(obj: ObjId, index: UInt64, value: String, marks: [String: Value] ) - case increment( - obj: ObjId, - prop: Prop, - value: Int64 + case increment(obj: ObjId, prop: Prop, value: Int64 ) - case conflict( - obj: ObjId, - prop: Prop + case conflict(obj: ObjId, prop: Prop ) - case deleteMap( - obj: ObjId, - key: String + case deleteMap(obj: ObjId, key: String ) - case deleteSeq( - obj: ObjId, - index: UInt64, - length: UInt64 + case deleteSeq(obj: ObjId, index: UInt64, length: UInt64 ) - case marks( - obj: ObjId, - marks: [Mark] + case marks(obj: ObjId, marks: [Mark] ) } + public struct FfiConverterTypePatchAction: FfiConverterRustBuffer { typealias SwiftType = PatchAction public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PatchAction { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .put( - obj: FfiConverterTypeObjId.read(from: &buf), - prop: FfiConverterTypeProp.read(from: &buf), - value: FfiConverterTypeValue.read(from: &buf) - ) - - case 2: return try .insert( - obj: FfiConverterTypeObjId.read(from: &buf), - index: FfiConverterUInt64.read(from: &buf), - values: FfiConverterSequenceTypeValue.read(from: &buf) - ) - - case 3: return try .spliceText( - obj: FfiConverterTypeObjId.read(from: &buf), - index: FfiConverterUInt64.read(from: &buf), - value: FfiConverterString.read(from: &buf), - marks: FfiConverterDictionaryStringTypeValue.read(from: &buf) - ) - - case 4: return try .increment( - obj: FfiConverterTypeObjId.read(from: &buf), - prop: FfiConverterTypeProp.read(from: &buf), - value: FfiConverterInt64.read(from: &buf) - ) - - case 5: return try .conflict( - obj: FfiConverterTypeObjId.read(from: &buf), - prop: FfiConverterTypeProp.read(from: &buf) - ) - - case 6: return try .deleteMap( - obj: FfiConverterTypeObjId.read(from: &buf), - key: FfiConverterString.read(from: &buf) - ) - - case 7: return try .deleteSeq( - obj: FfiConverterTypeObjId.read(from: &buf), - index: FfiConverterUInt64.read(from: &buf), - length: FfiConverterUInt64.read(from: &buf) - ) - - case 8: return try .marks( - obj: FfiConverterTypeObjId.read(from: &buf), - marks: FfiConverterSequenceTypeMark.read(from: &buf) - ) - + + case 1: return .put(obj: try FfiConverterTypeObjId.read(from: &buf), prop: try FfiConverterTypeProp.read(from: &buf), value: try FfiConverterTypeValue.read(from: &buf) + ) + + case 2: return .insert(obj: try FfiConverterTypeObjId.read(from: &buf), index: try FfiConverterUInt64.read(from: &buf), values: try FfiConverterSequenceTypeValue.read(from: &buf) + ) + + case 3: return .spliceText(obj: try FfiConverterTypeObjId.read(from: &buf), index: try FfiConverterUInt64.read(from: &buf), value: try FfiConverterString.read(from: &buf), marks: try FfiConverterDictionaryStringTypeValue.read(from: &buf) + ) + + case 4: return .increment(obj: try FfiConverterTypeObjId.read(from: &buf), prop: try FfiConverterTypeProp.read(from: &buf), value: try FfiConverterInt64.read(from: &buf) + ) + + case 5: return .conflict(obj: try FfiConverterTypeObjId.read(from: &buf), prop: try FfiConverterTypeProp.read(from: &buf) + ) + + case 6: return .deleteMap(obj: try FfiConverterTypeObjId.read(from: &buf), key: try FfiConverterString.read(from: &buf) + ) + + case 7: return .deleteSeq(obj: try FfiConverterTypeObjId.read(from: &buf), index: try FfiConverterUInt64.read(from: &buf), length: try FfiConverterUInt64.read(from: &buf) + ) + + case 8: return .marks(obj: try FfiConverterTypeObjId.read(from: &buf), marks: try FfiConverterSequenceTypeMark.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: PatchAction, into buf: inout [UInt8]) { switch value { - case let .put(obj, prop, value): + + + case let .put(obj,prop,value): writeInt(&buf, Int32(1)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterTypeProp.write(prop, into: &buf) FfiConverterTypeValue.write(value, into: &buf) - - case let .insert(obj, index, values): + + + case let .insert(obj,index,values): writeInt(&buf, Int32(2)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterUInt64.write(index, into: &buf) FfiConverterSequenceTypeValue.write(values, into: &buf) - - case let .spliceText(obj, index, value, marks): + + + case let .spliceText(obj,index,value,marks): writeInt(&buf, Int32(3)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterUInt64.write(index, into: &buf) FfiConverterString.write(value, into: &buf) FfiConverterDictionaryStringTypeValue.write(marks, into: &buf) - - case let .increment(obj, prop, value): + + + case let .increment(obj,prop,value): writeInt(&buf, Int32(4)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterTypeProp.write(prop, into: &buf) FfiConverterInt64.write(value, into: &buf) - - case let .conflict(obj, prop): + + + case let .conflict(obj,prop): writeInt(&buf, Int32(5)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterTypeProp.write(prop, into: &buf) - - case let .deleteMap(obj, key): + + + case let .deleteMap(obj,key): writeInt(&buf, Int32(6)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterString.write(key, into: &buf) - - case let .deleteSeq(obj, index, length): + + + case let .deleteSeq(obj,index,length): writeInt(&buf, Int32(7)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterUInt64.write(index, into: &buf) FfiConverterUInt64.write(length, into: &buf) - - case let .marks(obj, marks): + + + case let .marks(obj,marks): writeInt(&buf, Int32(8)) FfiConverterTypeObjId.write(obj, into: &buf) FfiConverterSequenceTypeMark.write(marks, into: &buf) + } } } + public func FfiConverterTypePatchAction_lift(_ buf: RustBuffer) throws -> PatchAction { - try FfiConverterTypePatchAction.lift(buf) + return try FfiConverterTypePatchAction.lift(buf) } public func FfiConverterTypePatchAction_lower(_ value: PatchAction) -> RustBuffer { - FfiConverterTypePatchAction.lower(value) + return FfiConverterTypePatchAction.lower(value) } + + extension PatchAction: Equatable, Hashable {} + + // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum Prop { - case key( - value: String + + case key(value: String ) - case index( - value: UInt64 + case index(value: UInt64 ) } + public struct FfiConverterTypeProp: FfiConverterRustBuffer { typealias SwiftType = Prop public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Prop { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .key( - value: FfiConverterString.read(from: &buf) - ) - - case 2: return try .index( - value: FfiConverterUInt64.read(from: &buf) - ) - + + case 1: return .key(value: try FfiConverterString.read(from: &buf) + ) + + case 2: return .index(value: try FfiConverterUInt64.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: Prop, into buf: inout [UInt8]) { switch value { + + case let .key(value): writeInt(&buf, Int32(1)) FfiConverterString.write(value, into: &buf) - + + case let .index(value): writeInt(&buf, Int32(2)) FfiConverterUInt64.write(value, into: &buf) + } } } + public func FfiConverterTypeProp_lift(_ buf: RustBuffer) throws -> Prop { - try FfiConverterTypeProp.lift(buf) + return try FfiConverterTypeProp.lift(buf) } public func FfiConverterTypeProp_lower(_ value: Prop) -> RustBuffer { - FfiConverterTypeProp.lower(value) + return FfiConverterTypeProp.lower(value) } + + extension Prop: Equatable, Hashable {} + + + public enum ReceiveSyncError { - case Internal(message: String) + + + case Internal(message: String) + case InvalidMessage(message: String) + } + public struct FfiConverterTypeReceiveSyncError: FfiConverterRustBuffer { typealias SwiftType = ReceiveSyncError public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ReceiveSyncError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .Internal( - message: FfiConverterString.read(from: &buf) - ) - case 2: return try .InvalidMessage( - message: FfiConverterString.read(from: &buf) - ) + + + + case 1: return .Internal( + message: try FfiConverterString.read(from: &buf) + ) + + case 2: return .InvalidMessage( + message: try FfiConverterString.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } @@ -2228,214 +2217,227 @@ public struct FfiConverterTypeReceiveSyncError: FfiConverterRustBuffer { public static func write(_ value: ReceiveSyncError, into buf: inout [UInt8]) { switch value { - case .Internal(_ /* message is ignored*/ ): + + + + + case .Internal(_ /* message is ignored*/): writeInt(&buf, Int32(1)) - case .InvalidMessage(_ /* message is ignored*/ ): + case .InvalidMessage(_ /* message is ignored*/): writeInt(&buf, Int32(2)) + + } } } + extension ReceiveSyncError: Equatable, Hashable {} -extension ReceiveSyncError: Error {} +extension ReceiveSyncError: Error { } // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum ScalarValue { - case bytes( - value: [UInt8] + + case bytes(value: [UInt8] ) - case string( - value: String + case string(value: String ) - case uint( - value: UInt64 + case uint(value: UInt64 ) - case int( - value: Int64 + case int(value: Int64 ) - case f64( - value: Double + case f64(value: Double ) - case counter( - value: Int64 + case counter(value: Int64 ) - case timestamp( - value: Int64 + case timestamp(value: Int64 ) - case boolean( - value: Bool + case boolean(value: Bool ) - case unknown( - typeCode: UInt8, - data: [UInt8] + case unknown(typeCode: UInt8, data: [UInt8] ) case null } + public struct FfiConverterTypeScalarValue: FfiConverterRustBuffer { typealias SwiftType = ScalarValue public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ScalarValue { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .bytes( - value: FfiConverterSequenceUInt8.read(from: &buf) - ) - - case 2: return try .string( - value: FfiConverterString.read(from: &buf) - ) - - case 3: return try .uint( - value: FfiConverterUInt64.read(from: &buf) - ) - - case 4: return try .int( - value: FfiConverterInt64.read(from: &buf) - ) - - case 5: return try .f64( - value: FfiConverterDouble.read(from: &buf) - ) - - case 6: return try .counter( - value: FfiConverterInt64.read(from: &buf) - ) - - case 7: return try .timestamp( - value: FfiConverterInt64.read(from: &buf) - ) - - case 8: return try .boolean( - value: FfiConverterBool.read(from: &buf) - ) - - case 9: return try .unknown( - typeCode: FfiConverterUInt8.read(from: &buf), - data: FfiConverterSequenceUInt8.read(from: &buf) - ) - + + case 1: return .bytes(value: try FfiConverterSequenceUInt8.read(from: &buf) + ) + + case 2: return .string(value: try FfiConverterString.read(from: &buf) + ) + + case 3: return .uint(value: try FfiConverterUInt64.read(from: &buf) + ) + + case 4: return .int(value: try FfiConverterInt64.read(from: &buf) + ) + + case 5: return .f64(value: try FfiConverterDouble.read(from: &buf) + ) + + case 6: return .counter(value: try FfiConverterInt64.read(from: &buf) + ) + + case 7: return .timestamp(value: try FfiConverterInt64.read(from: &buf) + ) + + case 8: return .boolean(value: try FfiConverterBool.read(from: &buf) + ) + + case 9: return .unknown(typeCode: try FfiConverterUInt8.read(from: &buf), data: try FfiConverterSequenceUInt8.read(from: &buf) + ) + case 10: return .null - + default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: ScalarValue, into buf: inout [UInt8]) { switch value { + + case let .bytes(value): writeInt(&buf, Int32(1)) FfiConverterSequenceUInt8.write(value, into: &buf) - + + case let .string(value): writeInt(&buf, Int32(2)) FfiConverterString.write(value, into: &buf) - + + case let .uint(value): writeInt(&buf, Int32(3)) FfiConverterUInt64.write(value, into: &buf) - + + case let .int(value): writeInt(&buf, Int32(4)) FfiConverterInt64.write(value, into: &buf) - + + case let .f64(value): writeInt(&buf, Int32(5)) FfiConverterDouble.write(value, into: &buf) - + + case let .counter(value): writeInt(&buf, Int32(6)) FfiConverterInt64.write(value, into: &buf) - + + case let .timestamp(value): writeInt(&buf, Int32(7)) FfiConverterInt64.write(value, into: &buf) - + + case let .boolean(value): writeInt(&buf, Int32(8)) FfiConverterBool.write(value, into: &buf) - - case let .unknown(typeCode, data): + + + case let .unknown(typeCode,data): writeInt(&buf, Int32(9)) FfiConverterUInt8.write(typeCode, into: &buf) FfiConverterSequenceUInt8.write(data, into: &buf) - + + case .null: writeInt(&buf, Int32(10)) + } } } + public func FfiConverterTypeScalarValue_lift(_ buf: RustBuffer) throws -> ScalarValue { - try FfiConverterTypeScalarValue.lift(buf) + return try FfiConverterTypeScalarValue.lift(buf) } public func FfiConverterTypeScalarValue_lower(_ value: ScalarValue) -> RustBuffer { - FfiConverterTypeScalarValue.lower(value) + return FfiConverterTypeScalarValue.lower(value) } + + extension ScalarValue: Equatable, Hashable {} + + // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum Value { - case object( - typ: ObjType, - id: ObjId + + case object(typ: ObjType, id: ObjId ) - case scalar( - value: ScalarValue + case scalar(value: ScalarValue ) } + public struct FfiConverterTypeValue: FfiConverterRustBuffer { typealias SwiftType = Value public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Value { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .object( - typ: FfiConverterTypeObjType.read(from: &buf), - id: FfiConverterTypeObjId.read(from: &buf) - ) - - case 2: return try .scalar( - value: FfiConverterTypeScalarValue.read(from: &buf) - ) - + + case 1: return .object(typ: try FfiConverterTypeObjType.read(from: &buf), id: try FfiConverterTypeObjId.read(from: &buf) + ) + + case 2: return .scalar(value: try FfiConverterTypeScalarValue.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: Value, into buf: inout [UInt8]) { switch value { - case let .object(typ, id): + + + case let .object(typ,id): writeInt(&buf, Int32(1)) FfiConverterTypeObjType.write(typ, into: &buf) FfiConverterTypeObjId.write(id, into: &buf) - + + case let .scalar(value): writeInt(&buf, Int32(2)) FfiConverterTypeScalarValue.write(value, into: &buf) + } } } + public func FfiConverterTypeValue_lift(_ buf: RustBuffer) throws -> Value { - try FfiConverterTypeValue.lift(buf) + return try FfiConverterTypeValue.lift(buf) } public func FfiConverterTypeValue_lower(_ value: Value) -> RustBuffer { - FfiConverterTypeValue.lower(value) + return FfiConverterTypeValue.lower(value) } + + extension Value: Equatable, Hashable {} -private struct FfiConverterOptionString: FfiConverterRustBuffer { + + +fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2456,7 +2458,7 @@ private struct FfiConverterOptionString: FfiConverterRustBuffer { } } -private struct FfiConverterOptionTypeChange: FfiConverterRustBuffer { +fileprivate struct FfiConverterOptionTypeChange: FfiConverterRustBuffer { typealias SwiftType = Change? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2477,7 +2479,7 @@ private struct FfiConverterOptionTypeChange: FfiConverterRustBuffer { } } -private struct FfiConverterOptionTypeValue: FfiConverterRustBuffer { +fileprivate struct FfiConverterOptionTypeValue: FfiConverterRustBuffer { typealias SwiftType = Value? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2498,7 +2500,7 @@ private struct FfiConverterOptionTypeValue: FfiConverterRustBuffer { } } -private struct FfiConverterOptionSequenceUInt8: FfiConverterRustBuffer { +fileprivate struct FfiConverterOptionSequenceUInt8: FfiConverterRustBuffer { typealias SwiftType = [UInt8]? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2519,7 +2521,7 @@ private struct FfiConverterOptionSequenceUInt8: FfiConverterRustBuffer { } } -private struct FfiConverterOptionSequenceTypeChangeHash: FfiConverterRustBuffer { +fileprivate struct FfiConverterOptionSequenceTypeChangeHash: FfiConverterRustBuffer { typealias SwiftType = [ChangeHash]? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2540,7 +2542,7 @@ private struct FfiConverterOptionSequenceTypeChangeHash: FfiConverterRustBuffer } } -private struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { typealias SwiftType = [UInt8] public static func write(_ value: [UInt8], into buf: inout [UInt8]) { @@ -2556,13 +2558,13 @@ private struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { var seq = [UInt8]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterUInt8.read(from: &buf)) + seq.append(try FfiConverterUInt8.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceString: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] public static func write(_ value: [String], into buf: inout [UInt8]) { @@ -2578,13 +2580,13 @@ private struct FfiConverterSequenceString: FfiConverterRustBuffer { var seq = [String]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterString.read(from: &buf)) + seq.append(try FfiConverterString.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceTypeKeyValue: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceTypeKeyValue: FfiConverterRustBuffer { typealias SwiftType = [KeyValue] public static func write(_ value: [KeyValue], into buf: inout [UInt8]) { @@ -2600,13 +2602,13 @@ private struct FfiConverterSequenceTypeKeyValue: FfiConverterRustBuffer { var seq = [KeyValue]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterTypeKeyValue.read(from: &buf)) + seq.append(try FfiConverterTypeKeyValue.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceTypeMark: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceTypeMark: FfiConverterRustBuffer { typealias SwiftType = [Mark] public static func write(_ value: [Mark], into buf: inout [UInt8]) { @@ -2622,13 +2624,13 @@ private struct FfiConverterSequenceTypeMark: FfiConverterRustBuffer { var seq = [Mark]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterTypeMark.read(from: &buf)) + seq.append(try FfiConverterTypeMark.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceTypePatch: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceTypePatch: FfiConverterRustBuffer { typealias SwiftType = [Patch] public static func write(_ value: [Patch], into buf: inout [UInt8]) { @@ -2644,13 +2646,13 @@ private struct FfiConverterSequenceTypePatch: FfiConverterRustBuffer { var seq = [Patch]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterTypePatch.read(from: &buf)) + seq.append(try FfiConverterTypePatch.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceTypePathElement: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceTypePathElement: FfiConverterRustBuffer { typealias SwiftType = [PathElement] public static func write(_ value: [PathElement], into buf: inout [UInt8]) { @@ -2666,13 +2668,13 @@ private struct FfiConverterSequenceTypePathElement: FfiConverterRustBuffer { var seq = [PathElement]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterTypePathElement.read(from: &buf)) + seq.append(try FfiConverterTypePathElement.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceTypeScalarValue: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceTypeScalarValue: FfiConverterRustBuffer { typealias SwiftType = [ScalarValue] public static func write(_ value: [ScalarValue], into buf: inout [UInt8]) { @@ -2688,13 +2690,13 @@ private struct FfiConverterSequenceTypeScalarValue: FfiConverterRustBuffer { var seq = [ScalarValue]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterTypeScalarValue.read(from: &buf)) + seq.append(try FfiConverterTypeScalarValue.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceTypeValue: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceTypeValue: FfiConverterRustBuffer { typealias SwiftType = [Value] public static func write(_ value: [Value], into buf: inout [UInt8]) { @@ -2710,13 +2712,13 @@ private struct FfiConverterSequenceTypeValue: FfiConverterRustBuffer { var seq = [Value]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterTypeValue.read(from: &buf)) + seq.append(try FfiConverterTypeValue.read(from: &buf)) } return seq } } -private struct FfiConverterSequenceTypeChangeHash: FfiConverterRustBuffer { +fileprivate struct FfiConverterSequenceTypeChangeHash: FfiConverterRustBuffer { typealias SwiftType = [ChangeHash] public static func write(_ value: [ChangeHash], into buf: inout [UInt8]) { @@ -2732,13 +2734,13 @@ private struct FfiConverterSequenceTypeChangeHash: FfiConverterRustBuffer { var seq = [ChangeHash]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { - try seq.append(FfiConverterTypeChangeHash.read(from: &buf)) + seq.append(try FfiConverterTypeChangeHash.read(from: &buf)) } return seq } } -private struct FfiConverterDictionaryStringTypeValue: FfiConverterRustBuffer { +fileprivate struct FfiConverterDictionaryStringTypeValue: FfiConverterRustBuffer { public static func write(_ value: [String: Value], into buf: inout [UInt8]) { let len = Int32(value.count) writeInt(&buf, len) @@ -2752,7 +2754,7 @@ private struct FfiConverterDictionaryStringTypeValue: FfiConverterRustBuffer { let len: Int32 = try readInt(&buf) var dict = [String: Value]() dict.reserveCapacity(Int(len)) - for _ in 0 ..< len { + for _ in 0.. ActorId { - try FfiConverterSequenceUInt8.read(from: &buf) + return try FfiConverterSequenceUInt8.read(from: &buf) } public static func write(_ value: ActorId, into buf: inout [UInt8]) { - FfiConverterSequenceUInt8.write(value, into: &buf) + return FfiConverterSequenceUInt8.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> ActorId { - try FfiConverterSequenceUInt8.lift(value) + return try FfiConverterSequenceUInt8.lift(value) } public static func lower(_ value: ActorId) -> RustBuffer { - FfiConverterSequenceUInt8.lower(value) + return FfiConverterSequenceUInt8.lower(value) } } + public func FfiConverterTypeActorId_lift(_ value: RustBuffer) throws -> ActorId { - try FfiConverterTypeActorId.lift(value) + return try FfiConverterTypeActorId.lift(value) } public func FfiConverterTypeActorId_lower(_ value: ActorId) -> RustBuffer { - FfiConverterTypeActorId.lower(value) + return FfiConverterTypeActorId.lower(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. @@ -2799,30 +2805,33 @@ public func FfiConverterTypeActorId_lower(_ value: ActorId) -> RustBuffer { public typealias ChangeHash = [UInt8] public struct FfiConverterTypeChangeHash: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChangeHash { - try FfiConverterSequenceUInt8.read(from: &buf) + return try FfiConverterSequenceUInt8.read(from: &buf) } public static func write(_ value: ChangeHash, into buf: inout [UInt8]) { - FfiConverterSequenceUInt8.write(value, into: &buf) + return FfiConverterSequenceUInt8.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> ChangeHash { - try FfiConverterSequenceUInt8.lift(value) + return try FfiConverterSequenceUInt8.lift(value) } public static func lower(_ value: ChangeHash) -> RustBuffer { - FfiConverterSequenceUInt8.lower(value) + return FfiConverterSequenceUInt8.lower(value) } } + public func FfiConverterTypeChangeHash_lift(_ value: RustBuffer) throws -> ChangeHash { - try FfiConverterTypeChangeHash.lift(value) + return try FfiConverterTypeChangeHash.lift(value) } public func FfiConverterTypeChangeHash_lower(_ value: ChangeHash) -> RustBuffer { - FfiConverterTypeChangeHash.lower(value) + return FfiConverterTypeChangeHash.lower(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. @@ -2830,30 +2839,33 @@ public func FfiConverterTypeChangeHash_lower(_ value: ChangeHash) -> RustBuffer public typealias Cursor = [UInt8] public struct FfiConverterTypeCursor: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Cursor { - try FfiConverterSequenceUInt8.read(from: &buf) + return try FfiConverterSequenceUInt8.read(from: &buf) } public static func write(_ value: Cursor, into buf: inout [UInt8]) { - FfiConverterSequenceUInt8.write(value, into: &buf) + return FfiConverterSequenceUInt8.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> Cursor { - try FfiConverterSequenceUInt8.lift(value) + return try FfiConverterSequenceUInt8.lift(value) } public static func lower(_ value: Cursor) -> RustBuffer { - FfiConverterSequenceUInt8.lower(value) + return FfiConverterSequenceUInt8.lower(value) } } + public func FfiConverterTypeCursor_lift(_ value: RustBuffer) throws -> Cursor { - try FfiConverterTypeCursor.lift(value) + return try FfiConverterTypeCursor.lift(value) } public func FfiConverterTypeCursor_lower(_ value: Cursor) -> RustBuffer { - FfiConverterTypeCursor.lower(value) + return FfiConverterTypeCursor.lower(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. @@ -2861,36 +2873,36 @@ public func FfiConverterTypeCursor_lower(_ value: Cursor) -> RustBuffer { public typealias ObjId = [UInt8] public struct FfiConverterTypeObjId: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ObjId { - try FfiConverterSequenceUInt8.read(from: &buf) + return try FfiConverterSequenceUInt8.read(from: &buf) } public static func write(_ value: ObjId, into buf: inout [UInt8]) { - FfiConverterSequenceUInt8.write(value, into: &buf) + return FfiConverterSequenceUInt8.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> ObjId { - try FfiConverterSequenceUInt8.lift(value) + return try FfiConverterSequenceUInt8.lift(value) } public static func lower(_ value: ObjId) -> RustBuffer { - FfiConverterSequenceUInt8.lower(value) + return FfiConverterSequenceUInt8.lower(value) } } + public func FfiConverterTypeObjId_lift(_ value: RustBuffer) throws -> ObjId { - try FfiConverterTypeObjId.lift(value) + return try FfiConverterTypeObjId.lift(value) } public func FfiConverterTypeObjId_lower(_ value: ObjId) -> RustBuffer { - FfiConverterTypeObjId.lower(value) + return FfiConverterTypeObjId.lower(value) } public func root() -> ObjId { - try! FfiConverterTypeObjId.lift(try! rustCall { - uniffi_uniffi_automerge_fn_func_root( - $0 - ) - }) + return try! FfiConverterTypeObjId.lift(try! rustCall() { + uniffi_uniffi_automerge_fn_func_root($0 + ) +}) } private enum InitializationResult { @@ -2898,7 +2910,6 @@ private enum InitializationResult { case contractVersionMismatch case apiChecksumMismatch } - // Use a global variables to perform the versioning checks. Swift ensures that // the code inside is only computed once. private var initializationResult: InitializationResult { @@ -2909,205 +2920,208 @@ private var initializationResult: InitializationResult { if bindings_contract_version != scaffolding_contract_version { return InitializationResult.contractVersionMismatch } - if uniffi_uniffi_automerge_checksum_func_root() != 19647 { + if (uniffi_uniffi_automerge_checksum_func_root() != 19647) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_uniffi_automerge_checksum_method_doc_actor_id() != 10869) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_actor_id() != 10869 { + if (uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes() != 57114) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes() != 57114 { + if (uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes_with_patches() != 63928) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes_with_patches() != 63928 { + if (uniffi_uniffi_automerge_checksum_method_doc_change_by_hash() != 44577) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_change_by_hash() != 44577 { + if (uniffi_uniffi_automerge_checksum_method_doc_changes() != 1878) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_changes() != 1878 { + if (uniffi_uniffi_automerge_checksum_method_doc_commit_with() != 65319) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_commit_with() != 65319 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor() != 18441) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor() != 18441 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor_at() != 39363) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor_at() != 39363 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor_position() != 5760) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor_position() != 5760 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor_position_at() != 35233) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor_position_at() != 35233 { + if (uniffi_uniffi_automerge_checksum_method_doc_delete_in_list() != 36066) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_delete_in_list() != 36066 { + if (uniffi_uniffi_automerge_checksum_method_doc_delete_in_map() != 1721) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_delete_in_map() != 1721 { + if (uniffi_uniffi_automerge_checksum_method_doc_difference() != 13614) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_encode_changes_since() != 49806 { + if (uniffi_uniffi_automerge_checksum_method_doc_encode_changes_since() != 49806) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_encode_new_changes() != 56722 { + if (uniffi_uniffi_automerge_checksum_method_doc_encode_new_changes() != 56722) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_fork() != 38250 { + if (uniffi_uniffi_automerge_checksum_method_doc_fork() != 38250) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_fork_at() != 49724 { + if (uniffi_uniffi_automerge_checksum_method_doc_fork_at() != 49724) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_generate_sync_message() != 33156 { + if (uniffi_uniffi_automerge_checksum_method_doc_generate_sync_message() != 33156) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_all_at_in_list() != 42311 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_all_at_in_list() != 42311) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_all_at_in_map() != 29778 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_all_at_in_map() != 29778) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_all_in_list() != 3346 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_all_in_list() != 3346) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_all_in_map() != 46751 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_all_in_map() != 46751) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_at_in_list() != 29393 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_at_in_list() != 29393) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_at_in_map() != 41003 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_at_in_map() != 41003) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_in_list() != 55210 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_in_list() != 55210) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_get_in_map() != 27911 { + if (uniffi_uniffi_automerge_checksum_method_doc_get_in_map() != 27911) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_heads() != 44667 { + if (uniffi_uniffi_automerge_checksum_method_doc_heads() != 44667) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_increment_in_list() != 6803 { + if (uniffi_uniffi_automerge_checksum_method_doc_increment_in_list() != 6803) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_increment_in_map() != 24542 { + if (uniffi_uniffi_automerge_checksum_method_doc_increment_in_map() != 24542) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_insert_in_list() != 26167 { + if (uniffi_uniffi_automerge_checksum_method_doc_insert_in_list() != 26167) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_insert_object_in_list() != 30538 { + if (uniffi_uniffi_automerge_checksum_method_doc_insert_object_in_list() != 30538) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_length() != 30352 { + if (uniffi_uniffi_automerge_checksum_method_doc_length() != 30352) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_length_at() != 64377 { + if (uniffi_uniffi_automerge_checksum_method_doc_length_at() != 64377) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_map_entries() != 3918 { + if (uniffi_uniffi_automerge_checksum_method_doc_map_entries() != 3918) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_map_entries_at() != 35589 { + if (uniffi_uniffi_automerge_checksum_method_doc_map_entries_at() != 35589) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_map_keys() != 45893 { + if (uniffi_uniffi_automerge_checksum_method_doc_map_keys() != 45893) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_map_keys_at() != 36273 { + if (uniffi_uniffi_automerge_checksum_method_doc_map_keys_at() != 36273) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_mark() != 5875 { + if (uniffi_uniffi_automerge_checksum_method_doc_mark() != 5875) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_marks() != 58967 { + if (uniffi_uniffi_automerge_checksum_method_doc_marks() != 58967) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_marks_at() != 57491 { + if (uniffi_uniffi_automerge_checksum_method_doc_marks_at() != 57491) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_merge() != 8598 { + if (uniffi_uniffi_automerge_checksum_method_doc_merge() != 8598) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_merge_with_patches() != 63992 { + if (uniffi_uniffi_automerge_checksum_method_doc_merge_with_patches() != 63992) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_object_type() != 15479 { + if (uniffi_uniffi_automerge_checksum_method_doc_object_type() != 15479) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_path() != 29434 { + if (uniffi_uniffi_automerge_checksum_method_doc_path() != 29434) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_put_in_list() != 39558 { + if (uniffi_uniffi_automerge_checksum_method_doc_put_in_list() != 39558) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_put_in_map() != 3891 { + if (uniffi_uniffi_automerge_checksum_method_doc_put_in_map() != 3891) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_put_object_in_list() != 29333 { + if (uniffi_uniffi_automerge_checksum_method_doc_put_object_in_list() != 29333) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_put_object_in_map() != 50970 { + if (uniffi_uniffi_automerge_checksum_method_doc_put_object_in_map() != 50970) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_receive_sync_message() != 17509 { + if (uniffi_uniffi_automerge_checksum_method_doc_receive_sync_message() != 17509) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_receive_sync_message_with_patches() != 42532 { + if (uniffi_uniffi_automerge_checksum_method_doc_receive_sync_message_with_patches() != 42532) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_save() != 20308 { + if (uniffi_uniffi_automerge_checksum_method_doc_save() != 20308) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_set_actor() != 64337 { + if (uniffi_uniffi_automerge_checksum_method_doc_set_actor() != 64337) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_splice() != 29894 { + if (uniffi_uniffi_automerge_checksum_method_doc_splice() != 29894) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_splice_text() != 20602 { + if (uniffi_uniffi_automerge_checksum_method_doc_splice_text() != 20602) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_text() != 64716 { + if (uniffi_uniffi_automerge_checksum_method_doc_text() != 64716) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_text_at() != 45714 { + if (uniffi_uniffi_automerge_checksum_method_doc_text_at() != 45714) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_update_text() != 26364 { + if (uniffi_uniffi_automerge_checksum_method_doc_update_text() != 26364) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_values() != 48159 { + if (uniffi_uniffi_automerge_checksum_method_doc_values() != 48159) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_values_at() != 16206 { + if (uniffi_uniffi_automerge_checksum_method_doc_values_at() != 16206) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_syncstate_encode() != 34911 { + if (uniffi_uniffi_automerge_checksum_method_syncstate_encode() != 34911) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_syncstate_reset() != 57480 { + if (uniffi_uniffi_automerge_checksum_method_syncstate_reset() != 57480) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_syncstate_their_heads() != 39870 { + if (uniffi_uniffi_automerge_checksum_method_syncstate_their_heads() != 39870) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_constructor_doc_load() != 20048 { + if (uniffi_uniffi_automerge_checksum_constructor_doc_load() != 20048) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_constructor_doc_new() != 9447 { + if (uniffi_uniffi_automerge_checksum_constructor_doc_new() != 9447) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_constructor_doc_new_with_actor() != 21001 { + if (uniffi_uniffi_automerge_checksum_constructor_doc_new_with_actor() != 21001) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_constructor_syncstate_decode() != 17966 { + if (uniffi_uniffi_automerge_checksum_constructor_syncstate_decode() != 17966) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_constructor_syncstate_new() != 37569 { + if (uniffi_uniffi_automerge_checksum_constructor_syncstate_new() != 37569) { return InitializationResult.apiChecksumMismatch } @@ -3125,4 +3139,4 @@ private func uniffiEnsureInitialized() { } } -// swiftlint:enable all +// swiftlint:enable all \ No newline at end of file diff --git a/Sources/_CAutomergeUniffi/include/automergeFFI.h b/Sources/_CAutomergeUniffi/include/automergeFFI.h index 4b01c685..5efed78d 100644 --- a/Sources/_CAutomergeUniffi/include/automergeFFI.h +++ b/Sources/_CAutomergeUniffi/include/automergeFFI.h @@ -337,6 +337,11 @@ void uniffi_uniffi_automerge_fn_method_doc_delete_in_list(void*_Nonnull ptr, Rus void uniffi_uniffi_automerge_fn_method_doc_delete_in_map(void*_Nonnull ptr, RustBuffer obj, RustBuffer key, RustCallStatus *_Nonnull out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_DIFFERENCE +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_DIFFERENCE +RustBuffer uniffi_uniffi_automerge_fn_method_doc_difference(void*_Nonnull ptr, RustBuffer before, RustBuffer after, RustCallStatus *_Nonnull out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_ENCODE_CHANGES_SINCE #define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_ENCODE_CHANGES_SINCE RustBuffer uniffi_uniffi_automerge_fn_method_doc_encode_changes_since(void*_Nonnull ptr, RustBuffer heads, RustCallStatus *_Nonnull out_status @@ -965,6 +970,12 @@ uint16_t uniffi_uniffi_automerge_checksum_method_doc_delete_in_list(void #define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_DELETE_IN_MAP uint16_t uniffi_uniffi_automerge_checksum_method_doc_delete_in_map(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_DIFFERENCE +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_DIFFERENCE +uint16_t uniffi_uniffi_automerge_checksum_method_doc_difference(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_ENCODE_CHANGES_SINCE