diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b81bc627..bb7ae966 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,58 +6,123 @@ on: branches: [main] jobs: - build-test: + + automerge-dependencies: runs-on: macos-14 env: LOCAL_BUILD: true DEVELOPER_DIR: /Applications/Xcode_15.4.app + concurrency: + group: automerge-dependencies-${{ github.head_ref || github.run_id }} + cancel-in-progress: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Cache Automerge XCFramework and library + id: cache-automerge + uses: actions/cache@v4 + with: + path: | + automergeFFI.xcframework + automergeFFI.xcframework.zip + libuniffi_automerge.a + libuniffi_automerge_threads.a + key: automerge-dependencies-{{ hashFiles(AutomergeUniffi/automerge.swift) }}-{{ hashFiles(rust/Cargo.lock) }} - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.78.0 + toolchain: 1.81.0 default: true - - name: get xcode information - run: | - xcodebuild -version - swift --version - - name: build xcframework + - name: Select Xcode 15.4 + run: sudo xcode-select -s /Applications/Xcode_15.4.app + - name: Build Automerge XCFramework and library + if: steps.cache-automerge.outputs.cache-hit != 'true' run: ./scripts/build-xcframework.sh - - name: compress framework + - name: Compress Automerge XCFramework + if: steps.cache-automerge.outputs.cache-hit != 'true' run: ./scripts/compress-framework.sh + - uses: actions/upload-artifact@v4 + if: steps.cache-automerge.outputs.cache-hit != 'true' + with: + name: libuniffi_automerge + path: | + libuniffi_automerge.a + libuniffi_automerge_threads.a + + mac: + runs-on: macos-14 + needs: automerge-dependencies + steps: + - uses: actions/checkout@v4 + - name: Select Xcode 15.4 + run: sudo xcode-select -s /Applications/Xcode_15.4.app + - name: Restore Automerge XCFramework and library + uses: actions/cache/restore@v4 + with: + path: | + automergeFFI.xcframework + automergeFFI.xcframework.zip + libuniffi_automerge.a + libuniffi_automerge_threads.a + key: automerge-dependencies-{{ hashFiles(AutomergeUniffi/automerge.swift) }}-{{ hashFiles(rust/Cargo.lock) }} + - name: Get swift version + run: swift --version - name: Swift tests run: swift test - build-wasm32-unknown-wasi: + wasm: runs-on: ubuntu-latest + needs: automerge-dependencies + strategy: + matrix: + include: + - toolchain: swift-DEVELOPMENT-SNAPSHOT-2024-10-08-a + swift-sdk: swift-wasm-DEVELOPMENT-SNAPSHOT-2024-10-15-a + checksum: 229cd9d3b0ed582c7ef7c3064888ad78764e4743b5a770df92554a94513f53fb steps: - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: 1.78.0 - default: true - - run: rustup target add wasm32-wasi - - uses: swiftwasm/setup-swiftwasm@v1 + - uses: bytecodealliance/actions/wasmtime/setup@v1 + - name: Restore Automerge XCFramework and library + uses: actions/cache/restore@v4 with: - swift-version: "wasm-5.9.1-RELEASE" - #- run: cargo build --manifest-path rust/Cargo.toml --target wasm32-wasi --release - - run: scripts/ci/wasi-regen-swift.sh - - uses: actions/upload-artifact@v4 + path: | + automergeFFI.xcframework + automergeFFI.xcframework.zip + libuniffi_automerge.a + libuniffi_automerge_threads.a + key: automerge-dependencies-{{ hashFiles(AutomergeUniffi/automerge.swift) }}-{{ hashFiles(rust/Cargo.lock) }} + - name: Cache Toolchain for WebAssembly + id: cache-wasm-toolchain + uses: actions/cache@v4 with: - name: libuniffi_automerge-wasm32-unknown-wasi.a - path: ./rust/target/wasm32-wasi/release/libuniffi_automerge.a - - run: swift build --triple wasm32-unknown-wasi + path: /tmp/swift-toolchain.tar.gz + key: wasm-toolchain-${{ matrix.checksum }} + - name: Download Toolchain for WebAssembly + if: steps.cache-wasm-toolchain.outputs.cache-hit != 'true' + run: | + SWIFT_TOOLCHAIN_TAG="${{ matrix.toolchain }}" + set -ex + curl -f -o /tmp/swift-toolchain.tar.gz "https://download.swift.org/development/ubuntu2204/$SWIFT_TOOLCHAIN_TAG/$SWIFT_TOOLCHAIN_TAG-ubuntu22.04.tar.gz" + - name: Install Swift and Swift SDK for WebAssembly + run: | + PREFIX=/opt/swift + SWIFT_SDK_TAG="${{ matrix.swift-sdk }}" + set -ex + sudo mkdir -p $PREFIX; sudo tar -xzf /tmp/swift-toolchain.tar.gz -C $PREFIX --strip-component 1 + $PREFIX/usr/bin/swift sdk install "https://github.com/swiftwasm/swift/releases/download/$SWIFT_SDK_TAG/$SWIFT_SDK_TAG-wasm32-unknown-wasi.artifactbundle.zip" --checksum ${{ matrix.checksum }} + echo "$PREFIX/usr/bin" >> $GITHUB_PATH + - name: Build tests + run: swift build --swift-sdk wasm32-unknown-wasi --build-tests -Xlinker "`pwd`/libuniffi_automerge.a" -Xlinker -z -Xlinker stack-size=$((1024 * 1024)) + - name: Run tests + run: wasmtime run --wasm max-wasm-stack=$((1024 * 1024)) --dir . .build/debug/AutomergePackageTests.wasm rustfmt: runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.78.0 + toolchain: 1.81.0 default: true components: rustfmt - name: Clippy @@ -66,11 +131,11 @@ jobs: clippy: runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.78.0 + toolchain: 1.81.0 default: true components: clippy - name: Clippy diff --git a/.gitignore b/.gitignore index a3c329ff..729b13d1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .vscode # generated WebAssembly library from build scripts libuniffi_automerge.a +libuniffi_automerge_threads.a # generated by the UniFFI build process and replicated into repos, # but not stored directly, since they're generated diff --git a/AutomergeUniffi/automerge.swift b/AutomergeUniffi/automerge.swift index 2abb0dfc..84c1c736 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,11 +48,13 @@ 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? - self.init(bytes: rustBuffer.data!, count: Int(rustBuffer.len)) + self.init( + bytesNoCopy: rustBuffer.data!, + count: Int(rustBuffer.len), + deallocator: .none + ) } } @@ -70,15 +72,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 +90,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 +141,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 { +// analogous to the Rust trait of the same name. +fileprivate protocol FfiConverter { associatedtype FfiType associatedtype SwiftType @@ -165,23 +167,32 @@ 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 { +#if swift(>=5.8) + @_documentation(visibility: private) +#endif public static func lift(_ value: FfiType) throws -> SwiftType { - value + return value } +#if swift(>=5.8) + @_documentation(visibility: private) +#endif 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 { +#if swift(>=5.8) + @_documentation(visibility: private) +#endif public static func lift(_ buf: RustBuffer) throws -> SwiftType { var reader = createReader(data: Data(rustBuffer: buf)) let value = try read(from: &reader) @@ -192,16 +203,18 @@ extension FfiConverterRustBuffer { return value } +#if swift(>=5.8) + @_documentation(visibility: private) +#endif 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 +240,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 @@ -254,70 +267,70 @@ private extension RustCallStatus { } private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: nil) + let neverThrow: ((RustBuffer) throws -> Never)? = nil + return try makeRustCall(callback, errorHandler: neverThrow) } -private func rustCallWithError( - _ errorHandler: @escaping (RustBuffer) throws -> Error, - _ callback: (UnsafeMutablePointer) -> T -) throws -> T { +private func rustCallWithError( + _ errorHandler: @escaping (RustBuffer) throws -> E, + _ callback: (UnsafeMutablePointer) -> T) throws -> T { try makeRustCall(callback, errorHandler: errorHandler) } -private func makeRustCall( +private func makeRustCall( _ callback: (UnsafeMutablePointer) -> T, - errorHandler: ((RustBuffer) throws -> Error)? + errorHandler: ((RustBuffer) throws -> E)? ) throws -> T { uniffiEnsureInitialized() - var callStatus = RustCallStatus() + var callStatus = RustCallStatus.init() let returnedVal = callback(&callStatus) try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) return returnedVal } -private func uniffiCheckCallStatus( +private func uniffiCheckCallStatus( callStatus: RustCallStatus, - errorHandler: ((RustBuffer) throws -> Error)? + errorHandler: ((RustBuffer) throws -> E)? ) 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 +339,7 @@ private func uniffiTraitInterfaceCall( private func uniffiTraitInterfaceCallWithError( callStatus: UnsafeMutablePointer, makeCall: () throws -> T, - writeReturn: (T) -> Void, + writeReturn: (T) -> (), lowerError: (E) -> RustBuffer ) { do { @@ -339,8 +352,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 +366,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 +386,25 @@ private class UniffiHandleMap { } var count: Int { - map.count + get { + map.count + } } } + // Public interface members begin here. -private struct FfiConverterUInt8: FfiConverterPrimitive { + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +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 +412,15 @@ private struct FfiConverterUInt8: FfiConverterPrimitive { } } -private struct FfiConverterUInt32: FfiConverterPrimitive { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt32: FfiConverterPrimitive { typealias FfiType = UInt32 typealias SwiftType = UInt32 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 { - try lift(readInt(&buf)) + return try lift(readInt(&buf)) } public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -406,12 +428,15 @@ private struct FfiConverterUInt32: FfiConverterPrimitive { } } -private struct FfiConverterUInt64: FfiConverterPrimitive { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +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]) { @@ -419,12 +444,15 @@ private struct FfiConverterUInt64: FfiConverterPrimitive { } } -private struct FfiConverterInt64: FfiConverterPrimitive { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +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]) { @@ -432,12 +460,15 @@ private struct FfiConverterInt64: FfiConverterPrimitive { } } -private struct FfiConverterDouble: FfiConverterPrimitive { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +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]) { @@ -445,20 +476,23 @@ private struct FfiConverterDouble: FfiConverterPrimitive { } } -private struct FfiConverterBool: FfiConverter { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +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]) { @@ -466,7 +500,10 @@ private struct FfiConverterBool: FfiConverter { } } -private struct FfiConverterString: FfiConverter { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterString: FfiConverter { typealias SwiftType = String typealias FfiType = RustBuffer @@ -482,7 +519,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. @@ -494,7 +531,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]) { @@ -504,138 +541,145 @@ 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 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 joinBlock(obj: ObjId, index: UInt32) throws - - 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 marksAtPosition(obj: ObjId, position: Position, 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 splitBlock(obj: ObjId, index: UInt32) throws -> ObjId - - 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 joinBlock(obj: ObjId, index: UInt32) throws + + 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 marksAtPosition(obj: ObjId, position: Position, 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 splitBlock(obj: ObjId, index: UInt32) throws -> ObjId + + 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif public struct NoPointer { public init() {} } @@ -643,745 +687,616 @@ 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]. - /// - /// - 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 + // 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]. + // + // - 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil } +#if swift(>=5.8) + @_documentation(visibility: private) +#endif 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) - } - - deinit { - guard let pointer = pointer else { - return - } - - 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 difference(before: [ChangeHash], after: [ChangeHash]) -> [Patch] { - 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] { - 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 joinBlock(obj: ObjId, index: UInt32) throws { try rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_join_block( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt32.lower(index), - $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 marksAtPosition(obj: ObjId, position: Position, heads: [ChangeHash]) throws -> [Mark] { - try FfiConverterSequenceTypeMark.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_marks_at_position( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterTypePosition.lower(position), - 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 splitBlock(obj: ObjId, index: UInt32) throws -> ObjId { - try FfiConverterTypeObjId.lift(rustCallWithError(FfiConverterTypeDocError.lift) { - uniffi_uniffi_automerge_fn_method_doc_split_block( - self.uniffiClonePointer(), - FfiConverterTypeObjId.lower(obj), - FfiConverterUInt32.lower(index), - $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 - ) - }) + 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) +} - 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 - ) - }) - } + deinit { + guard let pointer = pointer else { + return + } - 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 - ) - } + try! rustCall { uniffi_uniffi_automerge_fn_free_doc(pointer, $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 - ) - }) - } + +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 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 joinBlock(obj: ObjId, index: UInt32)throws {try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_join_block(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt32.lower(index),$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 marksAtPosition(obj: ObjId, position: Position, heads: [ChangeHash])throws -> [Mark] { + return try FfiConverterSequenceTypeMark.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_marks_at_position(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterTypePosition.lower(position), + 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 splitBlock(obj: ObjId, index: UInt32)throws -> ObjId { + return try FfiConverterTypeObjId.lift(try rustCallWithError(FfiConverterTypeDocError.lift) { + uniffi_uniffi_automerge_fn_method_doc_split_block(self.uniffiClonePointer(), + FfiConverterTypeObjId.lower(obj), + FfiConverterUInt32.lower(index),$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 - ) - }) - } } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 { @@ -1389,7 +1304,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!) @@ -1402,28 +1317,44 @@ public struct FfiConverterTypeDoc: FfiConverter { } } + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeDoc_lift(_ pointer: UnsafeMutableRawPointer) throws -> Doc { - try FfiConverterTypeDoc.lift(pointer) + return try FfiConverterTypeDoc.lift(pointer) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif public struct NoPointer { public init() {} } @@ -1431,34 +1362,36 @@ 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]. - /// - /// - 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 + // 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]. + // + // - 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil } +#if swift(>=5.8) + @_documentation(visibility: private) +#endif 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 { @@ -1468,51 +1401,54 @@ 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 - ) - }) - } } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 { @@ -1520,7 +1456,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!) @@ -1533,14 +1469,24 @@ public struct FfiConverterTypeSyncState: FfiConverter { } } + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeSyncState_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncState { - try FfiConverterTypeSyncState.lift(pointer) + return try FfiConverterTypeSyncState.lift(pointer) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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? @@ -1551,14 +1497,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 @@ -1568,8 +1507,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 } @@ -1601,15 +1542,20 @@ extension Change: Equatable, Hashable { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) ) } @@ -1623,14 +1569,22 @@ public struct FfiConverterTypeChange: FfiConverterRustBuffer { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeChange_lift(_ buf: RustBuffer) throws -> Change { - try FfiConverterTypeChange.lift(buf) + return try FfiConverterTypeChange.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 @@ -1643,8 +1597,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 } @@ -1660,11 +1616,16 @@ extension KeyValue: Equatable, Hashable { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) ) } @@ -1674,14 +1635,22 @@ public struct FfiConverterTypeKeyValue: FfiConverterRustBuffer { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeKeyValue_lift(_ buf: RustBuffer) throws -> KeyValue { - try FfiConverterTypeKeyValue.lift(buf) + return try FfiConverterTypeKeyValue.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 @@ -1698,8 +1667,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 } @@ -1723,13 +1694,18 @@ extension Mark: Equatable, Hashable { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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: FfiConverterTypeScalarValue.read(from: &buf) + return + try Mark( + start: FfiConverterUInt64.read(from: &buf), + end: FfiConverterUInt64.read(from: &buf), + name: FfiConverterString.read(from: &buf), + value: FfiConverterTypeScalarValue.read(from: &buf) ) } @@ -1741,14 +1717,22 @@ public struct FfiConverterTypeMark: FfiConverterRustBuffer { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeMark_lift(_ buf: RustBuffer) throws -> Mark { - try FfiConverterTypeMark.lift(buf) + return try FfiConverterTypeMark.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 @@ -1761,8 +1745,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 } @@ -1778,11 +1764,16 @@ extension Patch: Equatable, Hashable { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) ) } @@ -1792,14 +1783,22 @@ public struct FfiConverterTypePatch: FfiConverterRustBuffer { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypePatch_lift(_ buf: RustBuffer) throws -> Patch { - try FfiConverterTypePatch.lift(buf) + return try FfiConverterTypePatch.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 @@ -1812,8 +1811,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 } @@ -1829,11 +1830,16 @@ extension PathElement: Equatable, Hashable { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) ) } @@ -1843,27 +1849,48 @@ public struct FfiConverterTypePathElement: FfiConverterRustBuffer { } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypePathElement_lift(_ buf: RustBuffer) throws -> PathElement { - try FfiConverterTypePathElement.lift(buf) + return try FfiConverterTypePathElement.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypePathElement_lower(_ value: PathElement) -> RustBuffer { - FfiConverterTypePathElement.lower(value) + return FfiConverterTypePathElement.lower(value) } + public enum DecodeSyncStateError { + + + case Internal(message: String) + } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 } @@ -1871,35 +1898,60 @@ 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: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + public enum DocError { - case WrongObjectType(message: String) + + + case WrongObjectType(message: String) + case Internal(message: String) + } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 } @@ -1907,86 +1959,134 @@ 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: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} // 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 } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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)) + } } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeExpandMark_lift(_ buf: RustBuffer) throws -> ExpandMark { - try FfiConverterTypeExpandMark.lift(buf) + return try FfiConverterTypeExpandMark.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) + } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 } @@ -1994,351 +2094,415 @@ 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: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} // 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 } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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)) + } } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeObjType_lift(_ buf: RustBuffer) throws -> ObjType { - try FfiConverterTypeObjType.lift(buf) + return try FfiConverterTypeObjType.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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] ) } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) + } } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypePatchAction_lift(_ buf: RustBuffer) throws -> PatchAction { - try FfiConverterTypePatchAction.lift(buf) + return try FfiConverterTypePatchAction.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 Position { - case cursor( - position: Cursor + + case cursor(position: Cursor ) - case index( - position: UInt64 + case index(position: UInt64 ) } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public struct FfiConverterTypePosition: FfiConverterRustBuffer { typealias SwiftType = Position public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Position { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .cursor( - position: FfiConverterTypeCursor.read(from: &buf) - ) - - case 2: return try .index( - position: FfiConverterUInt64.read(from: &buf) - ) - + + case 1: return .cursor(position: try FfiConverterTypeCursor.read(from: &buf) + ) + + case 2: return .index(position: try FfiConverterUInt64.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: Position, into buf: inout [UInt8]) { switch value { + + case let .cursor(position): writeInt(&buf, Int32(1)) FfiConverterTypeCursor.write(position, into: &buf) - + + case let .index(position): writeInt(&buf, Int32(2)) FfiConverterUInt64.write(position, into: &buf) + } } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypePosition_lift(_ buf: RustBuffer) throws -> Position { - try FfiConverterTypePosition.lift(buf) + return try FfiConverterTypePosition.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypePosition_lower(_ value: Position) -> RustBuffer { - FfiConverterTypePosition.lower(value) + return FfiConverterTypePosition.lower(value) } + + extension Position: 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 ) } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) + } } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeProp_lift(_ buf: RustBuffer) throws -> Prop { - try FfiConverterTypeProp.lift(buf) + return try FfiConverterTypeProp.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) + } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 } @@ -2346,214 +2510,252 @@ 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: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} // 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 } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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)) + } } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeScalarValue_lift(_ buf: RustBuffer) throws -> ScalarValue { - try FfiConverterTypeScalarValue.lift(buf) + return try FfiConverterTypeScalarValue.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 ) } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) + } } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeValue_lift(_ buf: RustBuffer) throws -> Value { - try FfiConverterTypeValue.lift(buf) + return try FfiConverterTypeValue.lift(buf) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeValue_lower(_ value: Value) -> RustBuffer { - FfiConverterTypeValue.lower(value) + return FfiConverterTypeValue.lower(value) } + + extension Value: Equatable, Hashable {} -private struct FfiConverterOptionString: FfiConverterRustBuffer { + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2574,7 +2776,10 @@ private struct FfiConverterOptionString: FfiConverterRustBuffer { } } -private struct FfiConverterOptionTypeChange: FfiConverterRustBuffer { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionTypeChange: FfiConverterRustBuffer { typealias SwiftType = Change? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2595,7 +2800,10 @@ private struct FfiConverterOptionTypeChange: FfiConverterRustBuffer { } } -private struct FfiConverterOptionTypeValue: FfiConverterRustBuffer { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionTypeValue: FfiConverterRustBuffer { typealias SwiftType = Value? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2616,7 +2824,10 @@ private struct FfiConverterOptionTypeValue: FfiConverterRustBuffer { } } -private struct FfiConverterOptionSequenceUInt8: FfiConverterRustBuffer { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionSequenceUInt8: FfiConverterRustBuffer { typealias SwiftType = [UInt8]? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2637,7 +2848,10 @@ private struct FfiConverterOptionSequenceUInt8: FfiConverterRustBuffer { } } -private struct FfiConverterOptionSequenceTypeChangeHash: FfiConverterRustBuffer { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionSequenceTypeChangeHash: FfiConverterRustBuffer { typealias SwiftType = [ChangeHash]? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { @@ -2658,7 +2872,10 @@ private struct FfiConverterOptionSequenceTypeChangeHash: FfiConverterRustBuffer } } -private struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { typealias SwiftType = [UInt8] public static func write(_ value: [UInt8], into buf: inout [UInt8]) { @@ -2674,13 +2891,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] public static func write(_ value: [String], into buf: inout [UInt8]) { @@ -2696,13 +2916,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeKeyValue: FfiConverterRustBuffer { typealias SwiftType = [KeyValue] public static func write(_ value: [KeyValue], into buf: inout [UInt8]) { @@ -2718,13 +2941,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeMark: FfiConverterRustBuffer { typealias SwiftType = [Mark] public static func write(_ value: [Mark], into buf: inout [UInt8]) { @@ -2740,13 +2966,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypePatch: FfiConverterRustBuffer { typealias SwiftType = [Patch] public static func write(_ value: [Patch], into buf: inout [UInt8]) { @@ -2762,13 +2991,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypePathElement: FfiConverterRustBuffer { typealias SwiftType = [PathElement] public static func write(_ value: [PathElement], into buf: inout [UInt8]) { @@ -2784,13 +3016,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeScalarValue: FfiConverterRustBuffer { typealias SwiftType = [ScalarValue] public static func write(_ value: [ScalarValue], into buf: inout [UInt8]) { @@ -2806,13 +3041,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeValue: FfiConverterRustBuffer { typealias SwiftType = [Value] public static func write(_ value: [Value], into buf: inout [UInt8]) { @@ -2828,13 +3066,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeChangeHash: FfiConverterRustBuffer { typealias SwiftType = [ChangeHash] public static func write(_ value: [ChangeHash], into buf: inout [UInt8]) { @@ -2850,13 +3091,16 @@ 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 { +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterDictionaryStringTypeValue: FfiConverterRustBuffer { public static func write(_ value: [String: Value], into buf: inout [UInt8]) { let len = Int32(value.count) writeInt(&buf, len) @@ -2870,7 +3114,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..=5.8) +@_documentation(visibility: private) +#endif public struct FfiConverterTypeActorId: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> 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) } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeActorId_lift(_ value: RustBuffer) throws -> ActorId { - try FfiConverterTypeActorId.lift(value) + return try FfiConverterTypeActorId.lift(value) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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. */ public typealias ChangeHash = [UInt8] + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeChangeHash_lift(_ value: RustBuffer) throws -> ChangeHash { - try FfiConverterTypeChangeHash.lift(value) + return try FfiConverterTypeChangeHash.lift(value) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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. */ public typealias Cursor = [UInt8] + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeCursor_lift(_ value: RustBuffer) throws -> Cursor { - try FfiConverterTypeCursor.lift(value) + return try FfiConverterTypeCursor.lift(value) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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. */ public typealias ObjId = [UInt8] + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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) } } + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif public func FfiConverterTypeObjId_lift(_ value: RustBuffer) throws -> ObjId { - try FfiConverterTypeObjId.lift(value) + return try FfiConverterTypeObjId.lift(value) } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif 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 { @@ -3016,10 +3310,9 @@ private enum InitializationResult { case contractVersionMismatch case apiChecksumMismatch } - -// Use a global variables to perform the versioning checks. Swift ensures that +// Use a global variable to perform the versioning checks. Swift ensures that // the code inside is only computed once. -private var initializationResult: InitializationResult { +private var initializationResult: InitializationResult = { // Get the bindings contract version from our ComponentInterface let bindings_contract_version = 26 // Get the scaffolding contract version by calling the into the dylib @@ -3027,222 +3320,222 @@ 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 { + if (uniffi_uniffi_automerge_checksum_method_doc_actor_id() != 10869) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes() != 57114 { + if (uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes() != 57114) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes_with_patches() != 63928 { + if (uniffi_uniffi_automerge_checksum_method_doc_apply_encoded_changes_with_patches() != 63928) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_change_by_hash() != 44577 { + if (uniffi_uniffi_automerge_checksum_method_doc_change_by_hash() != 44577) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_changes() != 1878 { + if (uniffi_uniffi_automerge_checksum_method_doc_changes() != 1878) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_commit_with() != 65319 { + if (uniffi_uniffi_automerge_checksum_method_doc_commit_with() != 65319) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor() != 18441 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor() != 18441) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor_at() != 39363 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor_at() != 39363) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor_position() != 5760 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor_position() != 5760) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_cursor_position_at() != 35233 { + if (uniffi_uniffi_automerge_checksum_method_doc_cursor_position_at() != 35233) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_delete_in_list() != 36066 { + if (uniffi_uniffi_automerge_checksum_method_doc_delete_in_list() != 36066) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_delete_in_map() != 1721 { + if (uniffi_uniffi_automerge_checksum_method_doc_delete_in_map() != 1721) { return InitializationResult.apiChecksumMismatch } - if uniffi_uniffi_automerge_checksum_method_doc_difference() != 13614 { + 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_join_block() != 37348 { + if (uniffi_uniffi_automerge_checksum_method_doc_join_block() != 37348) { 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_marks_at_position() != 19243 { + if (uniffi_uniffi_automerge_checksum_method_doc_marks_at_position() != 19243) { 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_split_block() != 10956 { + if (uniffi_uniffi_automerge_checksum_method_doc_split_block() != 10956) { 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 } return InitializationResult.ok -} +}() private func uniffiEnsureInitialized() { switch initializationResult { @@ -3255,4 +3548,4 @@ private func uniffiEnsureInitialized() { } } -// swiftlint:enable all +// swiftlint:enable all \ No newline at end of file diff --git a/Package.swift b/Package.swift index fdc957d1..0253c74b 100644 --- a/Package.swift +++ b/Package.swift @@ -76,7 +76,7 @@ let package = Package( // On Apple platforms, this links the core Rust library through XCFramework. // On other platforms (such as WASM), end users will need to build the library // themselves and link it through the "swift build -Xlinker path/to/libuniffi_automerge.a" - // for example: cargo build --manifest-path rust/Cargo.toml --target wasm32-wasi --release + // for example: cargo build --manifest-path rust/Cargo.toml --target wasm32-wasip1 --release .target(name: "automergeFFI", condition: .when(platforms: [ .iOS, .macOS, .macCatalyst, .tvOS, .watchOS, .visionOS, ])), diff --git a/Sources/_CAutomergeUniffi/include/module.modulemap b/Sources/_CAutomergeUniffi/include/module.modulemap index efb04e79..b3eedf64 100644 --- a/Sources/_CAutomergeUniffi/include/module.modulemap +++ b/Sources/_CAutomergeUniffi/include/module.modulemap @@ -1,5 +1,3 @@ -// This file was autogenerated by some hot garbage in the `uniffi` crate. -// Trust me, you don't want to mess with it! module automergeFFI { header "automergeFFI.h" export * diff --git a/Tests/AutomergeTests/BoundTypeTests/BoundTypeChangeTests.swift b/Tests/AutomergeTests/BoundTypeTests/BoundTypeChangeTests.swift index 046c8c0b..9c0c2194 100644 --- a/Tests/AutomergeTests/BoundTypeTests/BoundTypeChangeTests.swift +++ b/Tests/AutomergeTests/BoundTypeTests/BoundTypeChangeTests.swift @@ -1,3 +1,4 @@ +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) @testable import Automerge import XCTest @@ -48,3 +49,4 @@ class BoundTypeChangeTests: XCTestCase { await fulfillment(of: [textChangeNotification], timeout: 1.0, enforceOrder: false) } } +#endif diff --git a/Tests/AutomergeTests/BoundTypeTests/TestCounter.swift b/Tests/AutomergeTests/BoundTypeTests/TestCounter.swift index 6c2ec71b..b273ed4a 100644 --- a/Tests/AutomergeTests/BoundTypeTests/TestCounter.swift +++ b/Tests/AutomergeTests/BoundTypeTests/TestCounter.swift @@ -28,10 +28,6 @@ class CounterTestCase: XCTestCase { } func testCounterMergingWithPut() throws { - XCTExpectFailure( - "Test failure illustrating put doesn't merge the same as increment", - options: XCTExpectedFailure.Options() - ) let doc1 = Document() try doc1.put(obj: ObjId.ROOT, key: "counter", value: .Counter(0)) @@ -42,17 +38,32 @@ class CounterTestCase: XCTestCase { try doc2.put(obj: ObjId.ROOT, key: "counter", value: .Counter(-1)) _ = doc2.save() - XCTAssertEqual(try doc1.get(obj: ObjId.ROOT, key: "counter"), Value.Scalar(.Counter(3))) - XCTAssertEqual(try doc2.get(obj: ObjId.ROOT, key: "counter"), Value.Scalar(.Counter(-1))) + let counter1 = try doc1.get(obj: ObjId.ROOT, key: "counter") + assertNonFatal(counter1 == Value.Scalar(.Counter(3)), "Test failure illustrating put doesn't merge the same as increment [\(counter1!) != \(Value.Scalar(.Counter(3)))]") + let counter2 = try doc2.get(obj: ObjId.ROOT, key: "counter") + assertNonFatal(counter2 == Value.Scalar(.Counter(-1)), "Test failure illustrating put doesn't merge the same as increment [\(counter2!) != \(Value.Scalar(.Counter(-1)))]") try doc1.merge(other: doc2) - XCTAssertEqual(try doc1.get(obj: ObjId.ROOT, key: "counter"), Value.Scalar(.Counter(2))) - XCTAssertEqual(try doc2.get(obj: ObjId.ROOT, key: "counter"), Value.Scalar(.Counter(-1))) - + let counter3 = try doc1.get(obj: ObjId.ROOT, key: "counter") + assertNonFatal(counter3 == Value.Scalar(.Counter(2)), "Test failure illustrating put doesn't merge the same as increment [\(counter3!) != \(Value.Scalar(.Counter(2)))]") + let counter4 = try doc2.get(obj: ObjId.ROOT, key: "counter") + assertNonFatal(counter4 == Value.Scalar(.Counter(-1)), "Test failure illustrating put doesn't merge the same as increment [\(counter4!) != \(Value.Scalar(.Counter(-1)))]") + try doc2.merge(other: doc1) - XCTAssertEqual(try doc1.get(obj: ObjId.ROOT, key: "counter"), Value.Scalar(.Counter(2))) - XCTAssertEqual(try doc2.get(obj: ObjId.ROOT, key: "counter"), Value.Scalar(.Counter(2))) + let counter5 = try doc1.get(obj: ObjId.ROOT, key: "counter") + assertNonFatal(counter5 == Value.Scalar(.Counter(2)), "Test failure illustrating put doesn't merge the same as increment [\(counter5!) != \(Value.Scalar(.Counter(2)))]") + + let counter6 = try doc2.get(obj: ObjId.ROOT, key: "counter") + assertNonFatal(counter6 == Value.Scalar(.Counter(2)), "Test failure illustrating put doesn't merge the same as increment [\(counter6!) != \(Value.Scalar(.Counter(2)))]") + } +} + +private extension XCTestCase { + func assertNonFatal(_ condition: Bool, _ message: String, file: StaticString = #file, line: UInt = #line) { + guard !condition else { return } + print("\(message) at \(file):\(line)") } } + diff --git a/Tests/AutomergeTests/InteropTests.swift b/Tests/AutomergeTests/InteropTests.swift index 82bd0c82..1472a515 100644 --- a/Tests/AutomergeTests/InteropTests.swift +++ b/Tests/AutomergeTests/InteropTests.swift @@ -1,3 +1,4 @@ +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) import Automerge import Foundation import XCTest @@ -111,3 +112,4 @@ class InteropTests: XCTestCase { // code, emphasis, line-break, strike-through, strong, etc. } } +#endif diff --git a/Tests/AutomergeTests/PresentationIntentsExplorationTest.swift b/Tests/AutomergeTests/PresentationIntentsExplorationTest.swift index 5729093e..b282f9b1 100644 --- a/Tests/AutomergeTests/PresentationIntentsExplorationTest.swift +++ b/Tests/AutomergeTests/PresentationIntentsExplorationTest.swift @@ -1,3 +1,4 @@ +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) import Foundation import SwiftUI import XCTest @@ -203,3 +204,4 @@ class PresentationIntentsExplorationTest: XCTestCase { } } #endif +#endif diff --git a/Tests/AutomergeTests/TestObservableDocument.swift b/Tests/AutomergeTests/TestObservableDocument.swift index 5ca405be..d1ab6ff4 100644 --- a/Tests/AutomergeTests/TestObservableDocument.swift +++ b/Tests/AutomergeTests/TestObservableDocument.swift @@ -1,3 +1,4 @@ +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) import Automerge import Combine import XCTest @@ -55,3 +56,4 @@ class ObservableDocumentTestCase: XCTestCase { XCTAssertNotEqual(doc.heads(), stashedHeads) } } +#endif diff --git a/Tests/AutomergeTests/TestWasmIntegrity.swift b/Tests/AutomergeTests/TestWasmIntegrity.swift new file mode 100644 index 00000000..1a1bc82d --- /dev/null +++ b/Tests/AutomergeTests/TestWasmIntegrity.swift @@ -0,0 +1,16 @@ +import Automerge +import XCTest + +class WasmIntegriy: XCTestCase { + + func testTextValueEncodingBetweenPlatforms() throws { + let doc = Document() + let textId = try doc.putObject(obj: .ROOT, key: "text", ty: .Text) + + try doc.spliceText(obj: textId, start: 0, delete: 0, value: "🇬🇧") + try doc.spliceText(obj: textId, start: UInt64("🇬🇧".unicodeScalars.count), delete: 0, value: "a") + let content = try doc.text(obj: textId) + + XCTAssertEqual(content, "🇬🇧a") + } +} diff --git a/notes/WebAssembly.md b/notes/WebAssembly.md index 55659074..37d2aafc 100644 --- a/notes/WebAssembly.md +++ b/notes/WebAssembly.md @@ -12,7 +12,7 @@ Swift-wasm with Swift package manager doesn't support invoking cargo to get the For example, the Rust core library (with the pieces needed to support Automerge-swift) can be built for wasm through Cargo using the command: - cargo build --manifest-path rust/Cargo.toml --target wasm32-wasi --release + cargo build --manifest-path rust/Cargo.toml --target wasm32-wasip1-threads --release This builds libuniffi_automerge.a, an archive of WebAssembly that can be linked and loaded by the swift-wasm compiler. The following snippet is an example of how to pass the library to swift-wasm builder on the command line: diff --git a/notes/release-process.md b/notes/release-process.md index 1e258d3c..49aee534 100644 --- a/notes/release-process.md +++ b/notes/release-process.md @@ -82,10 +82,12 @@ git push origin --tags - Add a release title - Add in a description for the release - Drag the file `automergeFFI.xcframework.zip` from the repository directory onto the github page to attach the binary. - - Drag the file `libuniffi_automerge.a` from the repository directory onto the github page to attach the binary. + - Drag the files `libuniffi_automerge.a` and `libuniffi_automerge_threads.a` from the repository directory onto the github page to attach the binary. - Wait for the upload to complete and verify the file is listed. - Select the checkout for a pre-release if relevant. +> `libuniffi_automerge_threads.a` is created using the [wasm32-wasip1-threads](https://doc.rust-lang.org/nightly/rustc/platform-support/wasm32-wasip1-threads.html#wasm32-wasip1-threads) target. + ![GitHub release page with tag selected, details filled, and binary uploaded.](./github_release_ready.png) (NOTE: the title and description details can be editing later without impact, but it is critically important to get the binary with the tag set as you expect - and that isn't editable if you miss it.) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 3efee8e9..d6973c5b 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -63,15 +63,17 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "automerge" -version = "0.5.11" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0b670b68c38e4042ea4826415f0f8101428810bce821d215e271966b24abac4" +checksum = "1f0dae93622d3c6850d196503480004576249e0e391bddb3f54600974d92a790" dependencies = [ + "cfg-if", "flate2", "fxhash", "hex", "im", "itertools", + "js-sys", "leb128", "serde", "sha2", @@ -81,6 +83,8 @@ dependencies = [ "tracing", "unicode-segmentation", "uuid", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -119,6 +123,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.5.0" @@ -258,8 +268,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -281,9 +293,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hex" @@ -307,9 +319,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] @@ -320,6 +332,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "leb128" version = "0.2.5" @@ -574,8 +595,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" dependencies = [ "smawk", - "unicode-linebreak", - "unicode-width", ] [[package]] @@ -674,31 +693,21 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-linebreak" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" - [[package]] name = "unicode-segmentation" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" -[[package]] -name = "unicode-width" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" - [[package]] name = "uniffi" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab38ff7ce5037772ca9bf7667e4e8535d110f11c6e2ec8cc9c1a7fc66938650c" +checksum = "51ce6280c581045879e11b400bae14686a819df22b97171215d15549efa04ddb" dependencies = [ "anyhow", + "cargo_metadata", + "uniffi_bindgen", "uniffi_build", "uniffi_core", "uniffi_macros", @@ -715,9 +724,9 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "480597c3b4074ab2faa39158f45f87f3ac33ccfd7bc7943ff0877372d9d8db97" +checksum = "5e9f25730c9db2e878521d606f54e921edb719cdd94d735e7f97705d6796d024" dependencies = [ "anyhow", "askama", @@ -733,15 +742,14 @@ dependencies = [ "textwrap", "toml", "uniffi_meta", - "uniffi_testing", "uniffi_udl", ] [[package]] name = "uniffi_build" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497391e423074ed5dbd828a2860d6203a333123519a285560c5ae1fd78075de4" +checksum = "88dba57ac699bd8ec53d6a352c8dd0e479b33f698c5659831bb1e4ce468c07bd" dependencies = [ "anyhow", "camino", @@ -750,9 +758,9 @@ dependencies = [ [[package]] name = "uniffi_checksum_derive" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95e86ccd44c138ba12b9132decbabeed84bf686ebe4b6538a5e489a243a7c2c9" +checksum = "d2c801f0f05b06df456a2da4c41b9c2c4fdccc6b9916643c6c67275c4c9e4d07" dependencies = [ "quote", "syn", @@ -760,13 +768,12 @@ dependencies = [ [[package]] name = "uniffi_core" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52fcb15ab907c37fe50163f05f97d497bc4400d8bfbdb7ef56b3a9ef777188d4" +checksum = "61049e4db6212d0ede80982adf0e1d6fa224e6118387324c5cfbe3083dfb2252" dependencies = [ "anyhow", "bytes", - "camino", "log", "once_cell", "paste", @@ -775,9 +782,9 @@ dependencies = [ [[package]] name = "uniffi_macros" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "865e2144b19552516c288e7c0425553c64724a8e4862bcb0c169355008e0ff0d" +checksum = "b40fd2249e0c5dcbd2bfa3c263db1ec981f7273dca7f4132bf06a272359a586c" dependencies = [ "bincode", "camino", @@ -793,9 +800,9 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7968bda370d74b9bffb9af1e9cdc9a354ce027dc313963860f26dcf6c8efcecf" +checksum = "c9ad57039b4fafdbf77428d74fff40e0908e5a1731e023c19cfe538f6d4a8ed6" dependencies = [ "anyhow", "bytes", @@ -805,9 +812,9 @@ dependencies = [ [[package]] name = "uniffi_testing" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfe857c83a2655412745e31929c05486d02b340336b595b7044eff342cf6c91" +checksum = "21fa171d4d258dc51bbd01893cc9608c1b62273d2f9ea55fb64f639e77824567" dependencies = [ "anyhow", "camino", @@ -818,9 +825,9 @@ dependencies = [ [[package]] name = "uniffi_udl" -version = "0.27.2" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af11dd5dd1a60d9af5ef30cd37f37090999d998be0c9d34d5ddaf6cee138ed4a" +checksum = "f52299e247419e7e2934bef2f94d7cccb0e6566f3248b1d48b160d8f369a2668" dependencies = [ "anyhow", "textwrap", @@ -837,6 +844,7 @@ checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ "getrandom", "serde", + "wasm-bindgen", ] [[package]] @@ -851,6 +859,71 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + +[[package]] +name = "web-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "weedle2" version = "5.0.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7b65eb26..8670c3f4 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -13,10 +13,9 @@ path = "uniffi-bindgen.rs" required-features = ["uniffi/cli"] [dependencies] -automerge = "0.5.11" +automerge = { version = "0.5.12", default-features = false, features = ["wasm"] } thiserror = "1.0.38" -uniffi = "0.27.1" +uniffi = "0.28.2" [build-dependencies] -uniffi = {version = "0.27.1", features = ["build"] } - +uniffi = { version = "0.28.2", features = ["build"] } diff --git a/rust/src/doc.rs b/rust/src/doc.rs index e115e5b8..b7b3c532 100644 --- a/rust/src/doc.rs +++ b/rust/src/doc.rs @@ -355,7 +355,9 @@ impl Doc { pub fn cursor_position(&self, obj: ObjId, cursor: Cursor) -> Result { let obj = am::ObjId::from(obj); let doc = self.0.read().unwrap(); - Ok(doc.get_cursor_position(obj, &cursor.into(), None).unwrap() as u64) + doc.get_cursor_position(obj, &cursor.into(), None) + .map(|cursor| cursor as u64) + .map_err(|error| DocError::Internal(error)) } pub fn cursor_position_at( @@ -370,9 +372,9 @@ impl Doc { .into_iter() .map(am::ChangeHash::from) .collect::>(); - Ok(doc - .get_cursor_position(obj, &cursor.into(), Some(&heads)) - .unwrap() as u64) + doc.get_cursor_position(obj, &cursor.into(), Some(&heads)) + .map(|cursor| cursor as u64) + .map_err(|error| DocError::Internal(error)) } pub fn text(&self, obj: ObjId) -> Result { diff --git a/scripts/build-xcframework.sh b/scripts/build-xcframework.sh index 33d72500..61f0fb15 100755 --- a/scripts/build-xcframework.sh +++ b/scripts/build-xcframework.sh @@ -46,7 +46,8 @@ rustup target add aarch64-apple-ios-sim # iOS Simulator (M1) rustup target add aarch64-apple-ios # iOS Device rustup target add aarch64-apple-darwin # macOS ARM/M1 rustup target add x86_64-apple-darwin # macOS Intel/x86 -rustup target add wasm32-wasi # WebAssembly +rustup target add wasm32-wasip1 # WebAssembly +rustup target add wasm32-wasip1-threads # WebAssembly with native multi threading capabilities cargo_build="cargo build --manifest-path $RUST_FOLDER/Cargo.toml" cargo_build_nightly="cargo +${RUST_NIGHTLY} build --manifest-path $RUST_FOLDER/Cargo.toml" cargo_build_nightly_with_std="cargo -Zbuild-std build --manifest-path $RUST_FOLDER/Cargo.toml" @@ -98,8 +99,9 @@ $cargo_build_nightly -Z build-std --target aarch64-apple-ios-macabi --locked --r echo "▸ Building for x86_64-apple-ios-macabi" $cargo_build_nightly -Z build-std --target x86_64-apple-ios-macabi --locked --release -echo "▸ Building for wasm32-wasi" -$cargo_build --target wasm32-wasi --locked --release +echo "▸ Building for WASM" +$cargo_build --target wasm32-wasip1 --locked --release +$cargo_build --target wasm32-wasip1-threads --locked --release echo "▸ Consolidating the headers and modulemaps for XCFramework generation" # copies the generated header from AutomergeUniffi/automergeFFI.h to @@ -191,4 +193,5 @@ cp ${PRIVACY_FOLDER}/PrivacyInfo.xcprivacy ${XCFRAMEWORK_FOLDER}/xros-arm64-simu echo "▸ Expose libuniffi_automerge.a WebAssembly archive" -cp "${BUILD_FOLDER}/wasm32-wasi/release/libuniffi_automerge.a" "$THIS_SCRIPT_DIR/../" +cp "${BUILD_FOLDER}/wasm32-wasip1/release/libuniffi_automerge.a" "$THIS_SCRIPT_DIR/../" +cp "${BUILD_FOLDER}/wasm32-wasip1-threads/release/libuniffi_automerge.a" "$THIS_SCRIPT_DIR/../libuniffi_automerge_threads.a" diff --git a/scripts/ci/wasi-regen-swift.sh b/scripts/ci/wasi-regen-swift.sh index 82af7b97..288b9129 100755 --- a/scripts/ci/wasi-regen-swift.sh +++ b/scripts/ci/wasi-regen-swift.sh @@ -10,11 +10,12 @@ set -euxo pipefail THIS_SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" -RUST_FOLDER="$THIS_SCRIPT_DIR/../../rust" +ROOT_FOLDER="$THIS_SCRIPT_DIR/../.." +RUST_FOLDER="$ROOT_FOLDER/rust" +SWIFT_FOLDER="$ROOT_FOLDER/AutomergeUniffi" FRAMEWORK_NAME="automergeFFI" -SWIFT_FOLDER="$THIS_SCRIPT_DIR/../../AutomergeUniffi" cargo_build="cargo build --manifest-path ${RUST_FOLDER}/Cargo.toml" mkdir -p "${SWIFT_FOLDER}" @@ -27,8 +28,11 @@ cargo run --manifest-path "$RUST_FOLDER/Cargo.toml" \ --language swift \ --out-dir "${SWIFT_FOLDER}" -echo "▸ Building for wasm32-wasi" -$cargo_build --target wasm32-wasi --locked --release +echo "▸ Building for WASM" +$cargo_build --target wasm32-wasip1 --locked --release +$cargo_build --target wasm32-wasip1-threads --locked --release +cp "${RUST_FOLDER}/target/wasm32-wasip1/release/libuniffi_automerge.a" "${ROOT_FOLDER}/libuniffi_automerge.a" +cp "${RUST_FOLDER}/target/wasm32-wasip1-threads/release/libuniffi_automerge.a" "${ROOT_FOLDER}/libuniffi_automerge_threads.a" # copies the generated header from AutomergeUniffi/automergeFFI.h to # Sources/_CAutomergeUniffi/include/automergeFFI.h within the project