From ea0616e198ac40117719d3b87c2b7e62ac0fc34a Mon Sep 17 00:00:00 2001 From: Jamil Date: Fri, 20 Jun 2025 11:40:48 -0700 Subject: [PATCH] chore(apple): ignore generated swift bridge files (#9599) Rust and Swift disagree about the formatting of these, leading to constant git file dirtiness when working on Apple code. These were originally added when we didn't have as much automation to regeneration these on each build. --- swift/apple/.gitignore | 1 + .../Connlib/Generated/SwiftBridgeCore.h | 164 -- .../Connlib/Generated/SwiftBridgeCore.swift | 1322 ----------------- .../apple-client-ffi/apple-client-ffi.h | 35 - .../apple-client-ffi/apple-client-ffi.swift | 204 --- 5 files changed, 1 insertion(+), 1725 deletions(-) delete mode 100644 swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h delete mode 100644 swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift delete mode 100644 swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.h delete mode 100644 swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.swift diff --git a/swift/apple/.gitignore b/swift/apple/.gitignore index bcaa61f6e..14615e0c0 100644 --- a/swift/apple/.gitignore +++ b/swift/apple/.gitignore @@ -5,3 +5,4 @@ DerivedData/ xcuserdata/ **/*.xcuserstate Firezone/xcconfig/dynamic_build_number.xcconfig +FirezoneNetworkExtension/Connlib/Generated/ diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h deleted file mode 100644 index b1b1f60ea..000000000 --- a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h +++ /dev/null @@ -1,164 +0,0 @@ -#include -#include -typedef struct RustStr { uint8_t* const start; uintptr_t len; } RustStr; -typedef struct __private__FfiSlice { void* const start; uintptr_t len; } __private__FfiSlice; -void* __swift_bridge__null_pointer(void); - - -typedef struct __private__OptionU8 { uint8_t val; bool is_some; } __private__OptionU8; -typedef struct __private__OptionI8 { int8_t val; bool is_some; } __private__OptionI8; -typedef struct __private__OptionU16 { uint16_t val; bool is_some; } __private__OptionU16; -typedef struct __private__OptionI16 { int16_t val; bool is_some; } __private__OptionI16; -typedef struct __private__OptionU32 { uint32_t val; bool is_some; } __private__OptionU32; -typedef struct __private__OptionI32 { int32_t val; bool is_some; } __private__OptionI32; -typedef struct __private__OptionU64 { uint64_t val; bool is_some; } __private__OptionU64; -typedef struct __private__OptionI64 { int64_t val; bool is_some; } __private__OptionI64; -typedef struct __private__OptionUsize { uintptr_t val; bool is_some; } __private__OptionUsize; -typedef struct __private__OptionIsize { intptr_t val; bool is_some; } __private__OptionIsize; -typedef struct __private__OptionF32 { float val; bool is_some; } __private__OptionF32; -typedef struct __private__OptionF64 { double val; bool is_some; } __private__OptionF64; -typedef struct __private__OptionBool { bool val; bool is_some; } __private__OptionBool; - -void* __swift_bridge__$Vec_u8$new(); -void __swift_bridge__$Vec_u8$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_u8$len(void* const vec); -void __swift_bridge__$Vec_u8$push(void* const vec, uint8_t val); -__private__OptionU8 __swift_bridge__$Vec_u8$pop(void* const vec); -__private__OptionU8 __swift_bridge__$Vec_u8$get(void* const vec, uintptr_t index); -__private__OptionU8 __swift_bridge__$Vec_u8$get_mut(void* const vec, uintptr_t index); -uint8_t const * __swift_bridge__$Vec_u8$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_u16$new(); -void __swift_bridge__$Vec_u16$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_u16$len(void* const vec); -void __swift_bridge__$Vec_u16$push(void* const vec, uint16_t val); -__private__OptionU16 __swift_bridge__$Vec_u16$pop(void* const vec); -__private__OptionU16 __swift_bridge__$Vec_u16$get(void* const vec, uintptr_t index); -__private__OptionU16 __swift_bridge__$Vec_u16$get_mut(void* const vec, uintptr_t index); -uint16_t const * __swift_bridge__$Vec_u16$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_u32$new(); -void __swift_bridge__$Vec_u32$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_u32$len(void* const vec); -void __swift_bridge__$Vec_u32$push(void* const vec, uint32_t val); -__private__OptionU32 __swift_bridge__$Vec_u32$pop(void* const vec); -__private__OptionU32 __swift_bridge__$Vec_u32$get(void* const vec, uintptr_t index); -__private__OptionU32 __swift_bridge__$Vec_u32$get_mut(void* const vec, uintptr_t index); -uint32_t const * __swift_bridge__$Vec_u32$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_u64$new(); -void __swift_bridge__$Vec_u64$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_u64$len(void* const vec); -void __swift_bridge__$Vec_u64$push(void* const vec, uint64_t val); -__private__OptionU64 __swift_bridge__$Vec_u64$pop(void* const vec); -__private__OptionU64 __swift_bridge__$Vec_u64$get(void* const vec, uintptr_t index); -__private__OptionU64 __swift_bridge__$Vec_u64$get_mut(void* const vec, uintptr_t index); -uint64_t const * __swift_bridge__$Vec_u64$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_usize$new(); -void __swift_bridge__$Vec_usize$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_usize$len(void* const vec); -void __swift_bridge__$Vec_usize$push(void* const vec, uintptr_t val); -__private__OptionUsize __swift_bridge__$Vec_usize$pop(void* const vec); -__private__OptionUsize __swift_bridge__$Vec_usize$get(void* const vec, uintptr_t index); -__private__OptionUsize __swift_bridge__$Vec_usize$get_mut(void* const vec, uintptr_t index); -uintptr_t const * __swift_bridge__$Vec_usize$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_i8$new(); -void __swift_bridge__$Vec_i8$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_i8$len(void* const vec); -void __swift_bridge__$Vec_i8$push(void* const vec, int8_t val); -__private__OptionI8 __swift_bridge__$Vec_i8$pop(void* const vec); -__private__OptionI8 __swift_bridge__$Vec_i8$get(void* const vec, uintptr_t index); -__private__OptionI8 __swift_bridge__$Vec_i8$get_mut(void* const vec, uintptr_t index); -int8_t const * __swift_bridge__$Vec_i8$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_i16$new(); -void __swift_bridge__$Vec_i16$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_i16$len(void* const vec); -void __swift_bridge__$Vec_i16$push(void* const vec, int16_t val); -__private__OptionI16 __swift_bridge__$Vec_i16$pop(void* const vec); -__private__OptionI16 __swift_bridge__$Vec_i16$get(void* const vec, uintptr_t index); -__private__OptionI16 __swift_bridge__$Vec_i16$get_mut(void* const vec, uintptr_t index); -int16_t const * __swift_bridge__$Vec_i16$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_i32$new(); -void __swift_bridge__$Vec_i32$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_i32$len(void* const vec); -void __swift_bridge__$Vec_i32$push(void* const vec, int32_t val); -__private__OptionI32 __swift_bridge__$Vec_i32$pop(void* const vec); -__private__OptionI32 __swift_bridge__$Vec_i32$get(void* const vec, uintptr_t index); -__private__OptionI32 __swift_bridge__$Vec_i32$get_mut(void* const vec, uintptr_t index); -int32_t const * __swift_bridge__$Vec_i32$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_i64$new(); -void __swift_bridge__$Vec_i64$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_i64$len(void* const vec); -void __swift_bridge__$Vec_i64$push(void* const vec, int64_t val); -__private__OptionI64 __swift_bridge__$Vec_i64$pop(void* const vec); -__private__OptionI64 __swift_bridge__$Vec_i64$get(void* const vec, uintptr_t index); -__private__OptionI64 __swift_bridge__$Vec_i64$get_mut(void* const vec, uintptr_t index); -int64_t const * __swift_bridge__$Vec_i64$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_isize$new(); -void __swift_bridge__$Vec_isize$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_isize$len(void* const vec); -void __swift_bridge__$Vec_isize$push(void* const vec, intptr_t val); -__private__OptionIsize __swift_bridge__$Vec_isize$pop(void* const vec); -__private__OptionIsize __swift_bridge__$Vec_isize$get(void* const vec, uintptr_t index); -__private__OptionIsize __swift_bridge__$Vec_isize$get_mut(void* const vec, uintptr_t index); -intptr_t const * __swift_bridge__$Vec_isize$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_bool$new(); -void __swift_bridge__$Vec_bool$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_bool$len(void* const vec); -void __swift_bridge__$Vec_bool$push(void* const vec, bool val); -__private__OptionBool __swift_bridge__$Vec_bool$pop(void* const vec); -__private__OptionBool __swift_bridge__$Vec_bool$get(void* const vec, uintptr_t index); -__private__OptionBool __swift_bridge__$Vec_bool$get_mut(void* const vec, uintptr_t index); -bool const * __swift_bridge__$Vec_bool$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_f32$new(); -void __swift_bridge__$Vec_f32$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_f32$len(void* const vec); -void __swift_bridge__$Vec_f32$push(void* const vec, float val); -__private__OptionF32 __swift_bridge__$Vec_f32$pop(void* const vec); -__private__OptionF32 __swift_bridge__$Vec_f32$get(void* const vec, uintptr_t index); -__private__OptionF32 __swift_bridge__$Vec_f32$get_mut(void* const vec, uintptr_t index); -float const * __swift_bridge__$Vec_f32$as_ptr(void* const vec); - -void* __swift_bridge__$Vec_f64$new(); -void __swift_bridge__$Vec_f64$_free(void* const vec); -uintptr_t __swift_bridge__$Vec_f64$len(void* const vec); -void __swift_bridge__$Vec_f64$push(void* const vec, double val); -__private__OptionF64 __swift_bridge__$Vec_f64$pop(void* const vec); -__private__OptionF64 __swift_bridge__$Vec_f64$get(void* const vec, uintptr_t index); -__private__OptionF64 __swift_bridge__$Vec_f64$get_mut(void* const vec, uintptr_t index); -double const * __swift_bridge__$Vec_f64$as_ptr(void* const vec); - -#include -typedef struct RustString RustString; -void __swift_bridge__$RustString$_free(void* self); - -void* __swift_bridge__$Vec_RustString$new(void); -void __swift_bridge__$Vec_RustString$drop(void* vec_ptr); -void __swift_bridge__$Vec_RustString$push(void* vec_ptr, void* item_ptr); -void* __swift_bridge__$Vec_RustString$pop(void* vec_ptr); -void* __swift_bridge__$Vec_RustString$get(void* vec_ptr, uintptr_t index); -void* __swift_bridge__$Vec_RustString$get_mut(void* vec_ptr, uintptr_t index); -uintptr_t __swift_bridge__$Vec_RustString$len(void* vec_ptr); -void* __swift_bridge__$Vec_RustString$as_ptr(void* vec_ptr); - -void* __swift_bridge__$RustString$new(void); -void* __swift_bridge__$RustString$new_with_str(struct RustStr str); -uintptr_t __swift_bridge__$RustString$len(void* self); -struct RustStr __swift_bridge__$RustString$as_str(void* self); -struct RustStr __swift_bridge__$RustString$trim(void* self); -bool __swift_bridge__$RustStr$partial_eq(struct RustStr lhs, struct RustStr rhs); - - -void __swift_bridge__$call_boxed_fn_once_no_args_no_return(void* boxed_fnonce); -void __swift_bridge__$free_boxed_fn_once_no_args_no_return(void* boxed_fnonce); - - -struct __private__ResultPtrAndPtr { bool is_ok; void* ok_or_err; }; diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift deleted file mode 100644 index 35d2e8acb..000000000 --- a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift +++ /dev/null @@ -1,1322 +0,0 @@ -import Foundation - -extension RustString { - public func toString() -> String { - let str = self.as_str() - let string = str.toString() - - return string - } -} - -extension RustStr { - func toBufferPointer() -> UnsafeBufferPointer { - let bytes = UnsafeBufferPointer(start: self.start, count: Int(self.len)) - return bytes - } - - public func toString() -> String { - let bytes = self.toBufferPointer() - return String(bytes: bytes, encoding: .utf8)! - } -} -extension RustStr: Identifiable { - public var id: String { - self.toString() - } -} -extension RustStr: Equatable { - public static func == (lhs: RustStr, rhs: RustStr) -> Bool { - return __swift_bridge__$RustStr$partial_eq(lhs, rhs); - } -} - -public protocol IntoRustString { - func intoRustString() -> RustString; -} - -extension String: IntoRustString { - public func intoRustString() -> RustString { - // TODO: When passing an owned Swift std String to Rust we've being wasteful here in that - // we're creating a RustString (which involves Boxing a Rust std::string::String) - // only to unbox it back into a String once it gets to the Rust side. - // - // A better approach would be to pass a RustStr to the Rust side and then have Rust - // call `.to_string()` on the RustStr. - RustString(self) - } -} - -extension RustString: IntoRustString { - public func intoRustString() -> RustString { - self - } -} - -/// If the String is Some: -/// Safely get a scoped pointer to the String and then call the callback with a RustStr -/// that uses that pointer. -/// -/// If the String is None: -/// Call the callback with a RustStr that has a null pointer. -/// The Rust side will know to treat this as `None`. -func optionalStringIntoRustString(_ string: Optional) -> RustString? { - if let val = string { - return val.intoRustString() - } else { - return nil - } -} - -/// Used to safely get a pointer to a sequence of utf8 bytes, represented as a `RustStr`. -/// -/// For example, the Swift `String` implementation of the `ToRustStr` protocol does the following: -/// 1. Use Swift's `String.utf8.withUnsafeBufferPointer` to get a pointer to the strings underlying -/// utf8 bytes. -/// 2. Construct a `RustStr` that points to these utf8 bytes. This is safe because `withUnsafeBufferPointer` -/// guarantees that the buffer pointer will be valid for the duration of the `withUnsafeBufferPointer` -/// callback. -/// 3. Pass the `RustStr` to the closure that was passed into `RustStr.toRustStr`. -public protocol ToRustStr { - func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T; -} - -extension String: ToRustStr { - /// Safely get a scoped pointer to the String and then call the callback with a RustStr - /// that uses that pointer. - public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { - return self.utf8CString.withUnsafeBufferPointer({ bufferPtr in - let rustStr = RustStr( - start: UnsafeMutableRawPointer(mutating: bufferPtr.baseAddress!).assumingMemoryBound(to: UInt8.self), - // Subtract 1 because of the null termination character at the end - len: UInt(bufferPtr.count - 1) - ) - return withUnsafeRustStr(rustStr) - }) - } -} - -extension RustStr: ToRustStr { - public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { - return withUnsafeRustStr(self) - } -} - -func optionalRustStrToRustStr(_ str: Optional, _ withUnsafeRustStr: (RustStr) -> T) -> T { - if let val = str { - return val.toRustStr(withUnsafeRustStr) - } else { - return withUnsafeRustStr(RustStr(start: nil, len: 0)) - } -} -public class RustVec { - var ptr: UnsafeMutableRawPointer - var isOwned: Bool = true - - public init(ptr: UnsafeMutableRawPointer) { - self.ptr = ptr - } - - public init() { - ptr = T.vecOfSelfNew() - isOwned = true - } - - public func push (value: T) { - T.vecOfSelfPush(vecPtr: ptr, value: value) - } - - public func pop () -> Optional { - T.vecOfSelfPop(vecPtr: ptr) - } - - public func get(index: UInt) -> Optional { - T.vecOfSelfGet(vecPtr: ptr, index: index) - } - - public func as_ptr() -> UnsafePointer { - UnsafePointer(OpaquePointer(T.vecOfSelfAsPtr(vecPtr: ptr))) - } - - /// Rust returns a UInt, but we cast to an Int because many Swift APIs such as - /// `ForEach(0..rustVec.len())` expect Int. - public func len() -> Int { - Int(T.vecOfSelfLen(vecPtr: ptr)) - } - - deinit { - if isOwned { - T.vecOfSelfFree(vecPtr: ptr) - } - } -} - -extension RustVec: Sequence { - public func makeIterator() -> RustVecIterator { - return RustVecIterator(self) - } -} - -public struct RustVecIterator: IteratorProtocol { - var rustVec: RustVec - var index: UInt = 0 - - init (_ rustVec: RustVec) { - self.rustVec = rustVec - } - - public mutating func next() -> T.SelfRef? { - let val = rustVec.get(index: index) - index += 1 - return val - } -} - -extension RustVec: Collection { - public typealias Index = Int - - public func index(after i: Int) -> Int { - i + 1 - } - - public subscript(position: Int) -> T.SelfRef { - self.get(index: UInt(position))! - } - - public var startIndex: Int { - 0 - } - - public var endIndex: Int { - self.len() - } -} - -extension RustVec: RandomAccessCollection {} - -extension UnsafeBufferPointer { - func toFfiSlice () -> __private__FfiSlice { - __private__FfiSlice(start: UnsafeMutablePointer(mutating: self.baseAddress), len: UInt(self.count)) - } -} - -public protocol Vectorizable { - associatedtype SelfRef - associatedtype SelfRefMut - - static func vecOfSelfNew() -> UnsafeMutableRawPointer; - - static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) - - static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) - - static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional - - static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional - - static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional - - static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer - - static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt -} - -extension UInt8: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_u8$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_u8$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_u8$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_u8$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u8$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u8$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u8$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_u8$len(vecPtr) - } -} - -extension UInt16: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_u16$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_u16$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_u16$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_u16$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u16$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u16$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u16$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_u16$len(vecPtr) - } -} - -extension UInt32: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_u32$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_u32$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_u32$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_u32$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u32$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u32$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u32$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_u32$len(vecPtr) - } -} - -extension UInt64: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_u64$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_u64$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_u64$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_u64$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u64$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_u64$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u64$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_u64$len(vecPtr) - } -} - -extension UInt: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_usize$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_usize$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_usize$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_usize$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_usize$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_usize$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_usize$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_usize$len(vecPtr) - } -} - -extension Int8: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_i8$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_i8$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_i8$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_i8$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i8$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i8$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i8$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_i8$len(vecPtr) - } -} - -extension Int16: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_i16$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_i16$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_i16$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_i16$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i16$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i16$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i16$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_i16$len(vecPtr) - } -} - -extension Int32: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_i32$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_i32$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_i32$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_i32$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i32$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i32$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i32$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_i32$len(vecPtr) - } -} - -extension Int64: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_i64$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_i64$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_i64$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_i64$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i64$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_i64$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i64$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_i64$len(vecPtr) - } -} - -extension Int: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_isize$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_isize$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_isize$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_isize$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_isize$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_isize$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_isize$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_isize$len(vecPtr) - } -} - -extension Bool: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_bool$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_bool$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_bool$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_bool$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_bool$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_bool$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_bool$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_bool$len(vecPtr) - } -} - -extension Float: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_f32$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_f32$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_f32$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_f32$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_f32$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_f32$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f32$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_f32$len(vecPtr) - } -} - -extension Double: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_f64$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_f64$_free(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { - __swift_bridge__$Vec_f64$push(vecPtr, value) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let val = __swift_bridge__$Vec_f64$pop(vecPtr) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_f64$get(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let val = __swift_bridge__$Vec_f64$get_mut(vecPtr, index) - if val.is_some { - return val.val - } else { - return nil - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f64$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_f64$len(vecPtr) - } -} - -protocol SwiftBridgeGenericFreer { - func rust_free(); -} - -protocol SwiftBridgeGenericCopyTypeFfiRepr {} - -public class RustString: RustStringRefMut { - var isOwned: Bool = true - - public override init(ptr: UnsafeMutableRawPointer) { - super.init(ptr: ptr) - } - - deinit { - if isOwned { - __swift_bridge__$RustString$_free(ptr) - } - } -} -extension RustString { - public convenience init() { - self.init(ptr: __swift_bridge__$RustString$new()) - } - - public convenience init(_ str: GenericToRustStr) { - self.init(ptr: str.toRustStr({ strAsRustStr in - __swift_bridge__$RustString$new_with_str(strAsRustStr) - })) - } -} -public class RustStringRefMut: RustStringRef { - public override init(ptr: UnsafeMutableRawPointer) { - super.init(ptr: ptr) - } -} -public class RustStringRef { - var ptr: UnsafeMutableRawPointer - - public init(ptr: UnsafeMutableRawPointer) { - self.ptr = ptr - } -} -extension RustStringRef { - public func len() -> UInt { - __swift_bridge__$RustString$len(ptr) - } - - public func as_str() -> RustStr { - __swift_bridge__$RustString$as_str(ptr) - } - - public func trim() -> RustStr { - __swift_bridge__$RustString$trim(ptr) - } -} -extension RustString: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_RustString$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_RustString$drop(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: RustString) { - __swift_bridge__$Vec_RustString$push(vecPtr, {value.isOwned = false; return value.ptr;}()) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let pointer = __swift_bridge__$Vec_RustString$pop(vecPtr) - if pointer == nil { - return nil - } else { - return (RustString(ptr: pointer!) as! Self) - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let pointer = __swift_bridge__$Vec_RustString$get(vecPtr, index) - if pointer == nil { - return nil - } else { - return RustStringRef(ptr: pointer!) - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let pointer = __swift_bridge__$Vec_RustString$get_mut(vecPtr, index) - if pointer == nil { - return nil - } else { - return RustStringRefMut(ptr: pointer!) - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_RustString$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_RustString$len(vecPtr) - } -} - -public class __private__RustFnOnceCallbackNoArgsNoRet { - var ptr: UnsafeMutableRawPointer - var called = false - - init(ptr: UnsafeMutableRawPointer) { - self.ptr = ptr - } - - deinit { - if !called { - __swift_bridge__$free_boxed_fn_once_no_args_no_return(ptr) - } - } - - func call() { - if called { - fatalError("Cannot call a Rust FnOnce function twice") - } - called = true - return __swift_bridge__$call_boxed_fn_once_no_args_no_return(ptr) - } -} - - -public enum RustResult { - case Ok(T) - case Err(E) -} - -extension RustResult { - func ok() -> T? { - switch self { - case .Ok(let ok): - return ok - case .Err(_): - return nil - } - } - - func err() -> E? { - switch self { - case .Ok(_): - return nil - case .Err(let err): - return err - } - } - - func toResult() -> Result - where E: Error { - switch self { - case .Ok(let ok): - return .success(ok) - case .Err(let err): - return .failure(err) - } - } -} - - -extension __private__OptionU8 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == UInt8 { - func intoFfiRepr() -> __private__OptionU8 { - __private__OptionU8(self) - } -} - -extension __private__OptionI8 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == Int8 { - func intoFfiRepr() -> __private__OptionI8 { - __private__OptionI8(self) - } -} - -extension __private__OptionU16 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == UInt16 { - func intoFfiRepr() -> __private__OptionU16 { - __private__OptionU16(self) - } -} - -extension __private__OptionI16 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == Int16 { - func intoFfiRepr() -> __private__OptionI16 { - __private__OptionI16(self) - } -} - -extension __private__OptionU32 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == UInt32 { - func intoFfiRepr() -> __private__OptionU32 { - __private__OptionU32(self) - } -} - -extension __private__OptionI32 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == Int32 { - func intoFfiRepr() -> __private__OptionI32 { - __private__OptionI32(self) - } -} - -extension __private__OptionU64 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == UInt64 { - func intoFfiRepr() -> __private__OptionU64 { - __private__OptionU64(self) - } -} - -extension __private__OptionI64 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == Int64 { - func intoFfiRepr() -> __private__OptionI64 { - __private__OptionI64(self) - } -} - -extension __private__OptionUsize { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == UInt { - func intoFfiRepr() -> __private__OptionUsize { - __private__OptionUsize(self) - } -} - -extension __private__OptionIsize { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123, is_some: false) - } - } -} -extension Optional where Wrapped == Int { - func intoFfiRepr() -> __private__OptionIsize { - __private__OptionIsize(self) - } -} - -extension __private__OptionF32 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123.4, is_some: false) - } - } -} -extension Optional where Wrapped == Float { - func intoFfiRepr() -> __private__OptionF32 { - __private__OptionF32(self) - } -} - -extension __private__OptionF64 { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: 123.4, is_some: false) - } - } -} -extension Optional where Wrapped == Double { - func intoFfiRepr() -> __private__OptionF64 { - __private__OptionF64(self) - } -} - -extension __private__OptionBool { - func intoSwiftRepr() -> Optional { - if self.is_some { - return self.val - } else { - return nil - } - } - - init(_ val: Optional) { - if let val = val { - self = Self(val: val, is_some: true) - } else { - self = Self(val: false, is_some: false) - } - } -} -extension Optional where Wrapped == Bool { - func intoFfiRepr() -> __private__OptionBool { - __private__OptionBool(self) - } -} diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.h b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.h deleted file mode 100644 index fbd671fcf..000000000 --- a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.h +++ /dev/null @@ -1,35 +0,0 @@ -// File automatically generated by swift-bridge. -#include -typedef struct DisconnectError DisconnectError; -void __swift_bridge__$DisconnectError$_free(void* self); - -void* __swift_bridge__$Vec_DisconnectError$new(void); -void __swift_bridge__$Vec_DisconnectError$drop(void* vec_ptr); -void __swift_bridge__$Vec_DisconnectError$push(void* vec_ptr, void* item_ptr); -void* __swift_bridge__$Vec_DisconnectError$pop(void* vec_ptr); -void* __swift_bridge__$Vec_DisconnectError$get(void* vec_ptr, uintptr_t index); -void* __swift_bridge__$Vec_DisconnectError$get_mut(void* vec_ptr, uintptr_t index); -uintptr_t __swift_bridge__$Vec_DisconnectError$len(void* vec_ptr); -void* __swift_bridge__$Vec_DisconnectError$as_ptr(void* vec_ptr); - -typedef struct WrappedSession WrappedSession; -void __swift_bridge__$WrappedSession$_free(void* self); - -void* __swift_bridge__$Vec_WrappedSession$new(void); -void __swift_bridge__$Vec_WrappedSession$drop(void* vec_ptr); -void __swift_bridge__$Vec_WrappedSession$push(void* vec_ptr, void* item_ptr); -void* __swift_bridge__$Vec_WrappedSession$pop(void* vec_ptr); -void* __swift_bridge__$Vec_WrappedSession$get(void* vec_ptr, uintptr_t index); -void* __swift_bridge__$Vec_WrappedSession$get_mut(void* vec_ptr, uintptr_t index); -uintptr_t __swift_bridge__$Vec_WrappedSession$len(void* vec_ptr); -void* __swift_bridge__$Vec_WrappedSession$as_ptr(void* vec_ptr); - -struct __private__ResultPtrAndPtr __swift_bridge__$WrappedSession$connect(void* api_url, void* token, void* device_id, void* account_slug, void* device_name_override, void* os_version_override, void* log_dir, void* log_filter, void* callback_handler, void* device_info); -void __swift_bridge__$WrappedSession$reset(void* self); -void* __swift_bridge__$WrappedSession$set_dns(void* self, void* dns_servers); -void* __swift_bridge__$WrappedSession$set_disabled_resources(void* self, void* disabled_resources); -void* __swift_bridge__$WrappedSession$set_log_directives(void* self, void* directives); -bool __swift_bridge__$DisconnectError$is_authentication_error(void* self); -void* __swift_bridge__$DisconnectError$to_string(void* self); - - diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.swift b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.swift deleted file mode 100644 index ffd4f065a..000000000 --- a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/apple-client-ffi/apple-client-ffi.swift +++ /dev/null @@ -1,204 +0,0 @@ -@_cdecl("__swift_bridge__$CallbackHandler$on_set_interface_config") -func __swift_bridge__CallbackHandler_on_set_interface_config (_ this: UnsafeMutableRawPointer, _ tunnelAddressIPv4: UnsafeMutableRawPointer, _ tunnelAddressIPv6: UnsafeMutableRawPointer, _ searchDomain: UnsafeMutableRawPointer?, _ dnsAddresses: UnsafeMutableRawPointer, _ routeListv4: UnsafeMutableRawPointer, _ routeListv6: UnsafeMutableRawPointer) { - Unmanaged.fromOpaque(this).takeUnretainedValue().onSetInterfaceConfig(tunnelAddressIPv4: RustString(ptr: tunnelAddressIPv4), tunnelAddressIPv6: RustString(ptr: tunnelAddressIPv6), searchDomain: { let val = searchDomain; if val != nil { return RustString(ptr: val!) } else { return nil } }(), dnsAddresses: RustString(ptr: dnsAddresses), routeListv4: RustString(ptr: routeListv4), routeListv6: RustString(ptr: routeListv6)) -} - -@_cdecl("__swift_bridge__$CallbackHandler$on_update_resources") -func __swift_bridge__CallbackHandler_on_update_resources (_ this: UnsafeMutableRawPointer, _ resourceList: UnsafeMutableRawPointer) { - Unmanaged.fromOpaque(this).takeUnretainedValue().onUpdateResources(resourceList: RustString(ptr: resourceList)) -} - -@_cdecl("__swift_bridge__$CallbackHandler$on_disconnect") -func __swift_bridge__CallbackHandler_on_disconnect (_ this: UnsafeMutableRawPointer, _ error: UnsafeMutableRawPointer) { - Unmanaged.fromOpaque(this).takeUnretainedValue().onDisconnect(error: DisconnectError(ptr: error)) -} - - -public class DisconnectError: DisconnectErrorRefMut { - var isOwned: Bool = true - - public override init(ptr: UnsafeMutableRawPointer) { - super.init(ptr: ptr) - } - - deinit { - if isOwned { - __swift_bridge__$DisconnectError$_free(ptr) - } - } -} -public class DisconnectErrorRefMut: DisconnectErrorRef { - public override init(ptr: UnsafeMutableRawPointer) { - super.init(ptr: ptr) - } -} -public class DisconnectErrorRef { - var ptr: UnsafeMutableRawPointer - - public init(ptr: UnsafeMutableRawPointer) { - self.ptr = ptr - } -} -extension DisconnectErrorRef { - public func isAuthenticationError() -> Bool { - __swift_bridge__$DisconnectError$is_authentication_error(ptr) - } - - public func toString() -> RustString { - RustString(ptr: __swift_bridge__$DisconnectError$to_string(ptr)) - } -} -extension DisconnectError: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_DisconnectError$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_DisconnectError$drop(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: DisconnectError) { - __swift_bridge__$Vec_DisconnectError$push(vecPtr, {value.isOwned = false; return value.ptr;}()) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let pointer = __swift_bridge__$Vec_DisconnectError$pop(vecPtr) - if pointer == nil { - return nil - } else { - return (DisconnectError(ptr: pointer!) as! Self) - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let pointer = __swift_bridge__$Vec_DisconnectError$get(vecPtr, index) - if pointer == nil { - return nil - } else { - return DisconnectErrorRef(ptr: pointer!) - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let pointer = __swift_bridge__$Vec_DisconnectError$get_mut(vecPtr, index) - if pointer == nil { - return nil - } else { - return DisconnectErrorRefMut(ptr: pointer!) - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_DisconnectError$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_DisconnectError$len(vecPtr) - } -} - - -public class WrappedSession: WrappedSessionRefMut { - var isOwned: Bool = true - - public override init(ptr: UnsafeMutableRawPointer) { - super.init(ptr: ptr) - } - - deinit { - if isOwned { - __swift_bridge__$WrappedSession$_free(ptr) - } - } -} -extension WrappedSession { - class public func connect(_ api_url: GenericIntoRustString, _ token: GenericIntoRustString, _ device_id: GenericIntoRustString, _ account_slug: GenericIntoRustString, _ device_name_override: Optional, _ os_version_override: Optional, _ log_dir: GenericIntoRustString, _ log_filter: GenericIntoRustString, _ callback_handler: CallbackHandler, _ device_info: GenericIntoRustString) throws -> WrappedSession { - try { let val = __swift_bridge__$WrappedSession$connect({ let rustString = api_url.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = token.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = device_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = account_slug.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { if let rustString = optionalStringIntoRustString(device_name_override) { rustString.isOwned = false; return rustString.ptr } else { return nil } }(), { if let rustString = optionalStringIntoRustString(os_version_override) { rustString.isOwned = false; return rustString.ptr } else { return nil } }(), { let rustString = log_dir.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = log_filter.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), Unmanaged.passRetained(callback_handler).toOpaque(), { let rustString = device_info.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val.is_ok { return WrappedSession(ptr: val.ok_or_err!) } else { throw RustString(ptr: val.ok_or_err!) } }() - } -} -public class WrappedSessionRefMut: WrappedSessionRef { - public override init(ptr: UnsafeMutableRawPointer) { - super.init(ptr: ptr) - } -} -extension WrappedSessionRefMut { - public func reset() { - __swift_bridge__$WrappedSession$reset(ptr) - } - - public func setDns(_ dns_servers: GenericIntoRustString) throws -> () { - try { let val = __swift_bridge__$WrappedSession$set_dns(ptr, { let rustString = dns_servers.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val != nil { throw RustString(ptr: val!) } else { return } }() - } - - public func setDisabledResources(_ disabled_resources: GenericIntoRustString) throws -> () { - try { let val = __swift_bridge__$WrappedSession$set_disabled_resources(ptr, { let rustString = disabled_resources.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val != nil { throw RustString(ptr: val!) } else { return } }() - } - - public func setLogDirectives(_ directives: GenericIntoRustString) throws -> () { - try { let val = __swift_bridge__$WrappedSession$set_log_directives(ptr, { let rustString = directives.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val != nil { throw RustString(ptr: val!) } else { return } }() - } -} -public class WrappedSessionRef { - var ptr: UnsafeMutableRawPointer - - public init(ptr: UnsafeMutableRawPointer) { - self.ptr = ptr - } -} -extension WrappedSession: Vectorizable { - public static func vecOfSelfNew() -> UnsafeMutableRawPointer { - __swift_bridge__$Vec_WrappedSession$new() - } - - public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { - __swift_bridge__$Vec_WrappedSession$drop(vecPtr) - } - - public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: WrappedSession) { - __swift_bridge__$Vec_WrappedSession$push(vecPtr, {value.isOwned = false; return value.ptr;}()) - } - - public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { - let pointer = __swift_bridge__$Vec_WrappedSession$pop(vecPtr) - if pointer == nil { - return nil - } else { - return (WrappedSession(ptr: pointer!) as! Self) - } - } - - public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let pointer = __swift_bridge__$Vec_WrappedSession$get(vecPtr, index) - if pointer == nil { - return nil - } else { - return WrappedSessionRef(ptr: pointer!) - } - } - - public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { - let pointer = __swift_bridge__$Vec_WrappedSession$get_mut(vecPtr, index) - if pointer == nil { - return nil - } else { - return WrappedSessionRefMut(ptr: pointer!) - } - } - - public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { - UnsafePointer(OpaquePointer(__swift_bridge__$Vec_WrappedSession$as_ptr(vecPtr))) - } - - public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { - __swift_bridge__$Vec_WrappedSession$len(vecPtr) - } -} - - -@_cdecl("__swift_bridge__$CallbackHandler$_free") -func __swift_bridge__CallbackHandler__free (ptr: UnsafeMutableRawPointer) { - let _ = Unmanaged.fromOpaque(ptr).takeRetainedValue() -} - - -