diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..843cd15 --- /dev/null +++ b/Package.swift @@ -0,0 +1,34 @@ +// swift-tools-version: 6.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "minimuxer", + products: [ + .library( + name: "minimuxer", + targets: ["minimuxer"]), + ], + targets: [ + .target( + name: "minimuxer", + dependencies: ["libminimuxer"]), + + .target( + name: "libminimuxer", + dependencies: ["minimuxer-binary"] + ), + + .binaryTarget( + name: "minimuxer-binary", + url: "https://github.com/SideStore/minimuxer/releases/download/build/minimuxer.xcframework.zip", + checksum: "0c3d526007e93e1570451473303f9d01f43d03847a986e12932de69d21cfe21a"), + + .testTarget( + name: "minimuxerTests", + dependencies: ["minimuxer"] + ), + ], + swiftLanguageModes: [.v5] +) diff --git a/Sources/libminimuxer/SwiftBridgeCore.h b/Sources/libminimuxer/SwiftBridgeCore.h new file mode 100644 index 0000000..b1b1f60 --- /dev/null +++ b/Sources/libminimuxer/SwiftBridgeCore.h @@ -0,0 +1,164 @@ +#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/Sources/libminimuxer/include/module.modulemap b/Sources/libminimuxer/include/module.modulemap new file mode 100644 index 0000000..216adb5 --- /dev/null +++ b/Sources/libminimuxer/include/module.modulemap @@ -0,0 +1,6 @@ +module libminimuxer { + header "../SwiftBridgeCore.h" + header "../minimuxer.h" + + export * +} diff --git a/Sources/libminimuxer/minimuxer.h b/Sources/libminimuxer/minimuxer.h new file mode 100644 index 0000000..d866f06 --- /dev/null +++ b/Sources/libminimuxer/minimuxer.h @@ -0,0 +1,88 @@ +// File automatically generated by swift-bridge. +#include +typedef struct __swift_bridge__$MinimuxerError$FieldOfInstallApp {void* _0;} __swift_bridge__$MinimuxerError$FieldOfInstallApp; +union __swift_bridge__$MinimuxerErrorFields { __swift_bridge__$MinimuxerError$FieldOfInstallApp InstallApp;}; +typedef enum __swift_bridge__$MinimuxerErrorTag { __swift_bridge__$MinimuxerError$NoDevice, __swift_bridge__$MinimuxerError$NoConnection, __swift_bridge__$MinimuxerError$PairingFile, __swift_bridge__$MinimuxerError$CreateDebug, __swift_bridge__$MinimuxerError$CreateInstproxy, __swift_bridge__$MinimuxerError$LookupApps, __swift_bridge__$MinimuxerError$FindApp, __swift_bridge__$MinimuxerError$BundlePath, __swift_bridge__$MinimuxerError$MaxPacket, __swift_bridge__$MinimuxerError$WorkingDirectory, __swift_bridge__$MinimuxerError$Argv, __swift_bridge__$MinimuxerError$LaunchSuccess, __swift_bridge__$MinimuxerError$Detach, __swift_bridge__$MinimuxerError$Attach, __swift_bridge__$MinimuxerError$CreateAfc, __swift_bridge__$MinimuxerError$RwAfc, __swift_bridge__$MinimuxerError$InstallApp, __swift_bridge__$MinimuxerError$UninstallApp, __swift_bridge__$MinimuxerError$CreateMisagent, __swift_bridge__$MinimuxerError$ProfileInstall, __swift_bridge__$MinimuxerError$ProfileRemove, } __swift_bridge__$MinimuxerErrorTag; +typedef struct __swift_bridge__$MinimuxerError { __swift_bridge__$MinimuxerErrorTag tag; union __swift_bridge__$MinimuxerErrorFields payload;} __swift_bridge__$MinimuxerError; +typedef struct __swift_bridge__$Option$MinimuxerError { bool is_some; __swift_bridge__$MinimuxerError val; } __swift_bridge__$Option$MinimuxerError; + +void* __swift_bridge__$describe_error(struct __swift_bridge__$MinimuxerError error); +bool __swift_bridge__$ready(void); +void __swift_bridge__$set_debug(bool debug); + + +// File automatically generated by swift-bridge. +#include +typedef struct RustDirectoryEntry RustDirectoryEntry; +void __swift_bridge__$RustDirectoryEntry$_free(void* self); + +void* __swift_bridge__$Vec_RustDirectoryEntry$new(void); +void __swift_bridge__$Vec_RustDirectoryEntry$drop(void* vec_ptr); +void __swift_bridge__$Vec_RustDirectoryEntry$push(void* vec_ptr, void* item_ptr); +void* __swift_bridge__$Vec_RustDirectoryEntry$pop(void* vec_ptr); +void* __swift_bridge__$Vec_RustDirectoryEntry$get(void* vec_ptr, uintptr_t index); +void* __swift_bridge__$Vec_RustDirectoryEntry$get_mut(void* vec_ptr, uintptr_t index); +uintptr_t __swift_bridge__$Vec_RustDirectoryEntry$len(void* vec_ptr); +void* __swift_bridge__$Vec_RustDirectoryEntry$as_ptr(void* vec_ptr); + +typedef struct AfcFileManager AfcFileManager; +void __swift_bridge__$AfcFileManager$_free(void* self); + +void* __swift_bridge__$Vec_AfcFileManager$new(void); +void __swift_bridge__$Vec_AfcFileManager$drop(void* vec_ptr); +void __swift_bridge__$Vec_AfcFileManager$push(void* vec_ptr, void* item_ptr); +void* __swift_bridge__$Vec_AfcFileManager$pop(void* vec_ptr); +void* __swift_bridge__$Vec_AfcFileManager$get(void* vec_ptr, uintptr_t index); +void* __swift_bridge__$Vec_AfcFileManager$get_mut(void* vec_ptr, uintptr_t index); +uintptr_t __swift_bridge__$Vec_AfcFileManager$len(void* vec_ptr); +void* __swift_bridge__$Vec_AfcFileManager$as_ptr(void* vec_ptr); + +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$AfcFileManager$remove(void* path); +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$AfcFileManager$create_directory(void* path); +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$AfcFileManager$write_file(void* to, struct __private__FfiSlice bytes); +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$AfcFileManager$copy_file_outside_afc(void* from, void* to); +void* __swift_bridge__$AfcFileManager$contents(void); +void* __swift_bridge__$RustDirectoryEntry$path(void* self); +void* __swift_bridge__$RustDirectoryEntry$parent(void* self); +bool __swift_bridge__$RustDirectoryEntry$is_file(void* self); +struct __private__OptionU32 __swift_bridge__$RustDirectoryEntry$size(void* self); +void* __swift_bridge__$RustDirectoryEntry$children(void* self); +typedef enum __swift_bridge__$ResultVoidAndErrors$Tag {__swift_bridge__$ResultVoidAndErrors$ResultOk, __swift_bridge__$ResultVoidAndErrors$ResultErr} __swift_bridge__$ResultVoidAndErrors$Tag; +union __swift_bridge__$ResultVoidAndErrors$Fields {struct __swift_bridge__$MinimuxerError err;}; +typedef struct __swift_bridge__$ResultVoidAndErrors{__swift_bridge__$ResultVoidAndErrors$Tag tag; union __swift_bridge__$ResultVoidAndErrors$Fields payload;} __swift_bridge__$ResultVoidAndErrors; + + +// File automatically generated by swift-bridge. +void* __swift_bridge__$fetch_udid(void); +bool __swift_bridge__$test_device_connection(void); + + +// File automatically generated by swift-bridge. +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$yeet_app_afc(void* bundle_id, struct __private__FfiSlice ipa_bytes); +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$install_ipa(void* bundle_id); +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$remove_app(void* bundle_id); + + +// File automatically generated by swift-bridge. +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$debug_app(void* app_id); +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$attach_debugger(uint32_t pid); + + +// File automatically generated by swift-bridge. +void __swift_bridge__$start_auto_mounter(void* docs_path); + + +// File automatically generated by swift-bridge. +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$start(void* pairing_file, void* log_path); +void __swift_bridge__$target_minimuxer_address(void); + + +// File automatically generated by swift-bridge. +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$install_provisioning_profile(struct __private__FfiSlice profile); +struct __swift_bridge__$ResultVoidAndErrors __swift_bridge__$remove_provisioning_profile(void* id); +struct __swift_bridge__$ResultStringAndErrors __swift_bridge__$dump_profiles(void* docs_path); +typedef enum __swift_bridge__$ResultStringAndErrors$Tag {__swift_bridge__$ResultStringAndErrors$ResultOk, __swift_bridge__$ResultStringAndErrors$ResultErr} __swift_bridge__$ResultStringAndErrors$Tag; +union __swift_bridge__$ResultStringAndErrors$Fields {void* ok; struct __swift_bridge__$MinimuxerError err;}; +typedef struct __swift_bridge__$ResultStringAndErrors{__swift_bridge__$ResultStringAndErrors$Tag tag; union __swift_bridge__$ResultStringAndErrors$Fields payload;} __swift_bridge__$ResultStringAndErrors; + + diff --git a/Sources/minimuxer/SwiftBridgeCore.swift b/Sources/minimuxer/SwiftBridgeCore.swift new file mode 100644 index 0000000..76cdb7d --- /dev/null +++ b/Sources/minimuxer/SwiftBridgeCore.swift @@ -0,0 +1,1323 @@ +import Foundation +import libminimuxer + +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/generated/minimuxer-helpers.swift b/Sources/minimuxer/minimuxer-helpers.swift similarity index 100% rename from generated/minimuxer-helpers.swift rename to Sources/minimuxer/minimuxer-helpers.swift diff --git a/Sources/minimuxer/minimuxer.swift b/Sources/minimuxer/minimuxer.swift new file mode 100644 index 0000000..4953088 --- /dev/null +++ b/Sources/minimuxer/minimuxer.swift @@ -0,0 +1,404 @@ +import Foundation +import libminimuxer + +public func describe_error(_ error: MinimuxerError) -> RustString { + RustString(ptr: __swift_bridge__$describe_error(error.intoFfiRepr())) +} +public func ready() -> Bool { + __swift_bridge__$ready() +} +public func set_debug(_ debug: Bool) { + __swift_bridge__$set_debug(debug) +} +public enum MinimuxerError { + case NoDevice + case NoConnection + case PairingFile + case CreateDebug + case CreateInstproxy + case LookupApps + case FindApp + case BundlePath + case MaxPacket + case WorkingDirectory + case Argv + case LaunchSuccess + case Detach + case Attach + case CreateAfc + case RwAfc + case InstallApp(RustString) + case UninstallApp + case CreateMisagent + case ProfileInstall + case ProfileRemove +} +extension MinimuxerError { + func intoFfiRepr() -> __swift_bridge__$MinimuxerError { + switch self { + case MinimuxerError.NoDevice: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$NoDevice; return val }() + case MinimuxerError.NoConnection: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$NoConnection; return val }() + case MinimuxerError.PairingFile: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$PairingFile; return val }() + case MinimuxerError.CreateDebug: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$CreateDebug; return val }() + case MinimuxerError.CreateInstproxy: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$CreateInstproxy; return val }() + case MinimuxerError.LookupApps: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$LookupApps; return val }() + case MinimuxerError.FindApp: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$FindApp; return val }() + case MinimuxerError.BundlePath: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$BundlePath; return val }() + case MinimuxerError.MaxPacket: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$MaxPacket; return val }() + case MinimuxerError.WorkingDirectory: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$WorkingDirectory; return val }() + case MinimuxerError.Argv: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$Argv; return val }() + case MinimuxerError.LaunchSuccess: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$LaunchSuccess; return val }() + case MinimuxerError.Detach: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$Detach; return val }() + case MinimuxerError.Attach: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$Attach; return val }() + case MinimuxerError.CreateAfc: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$CreateAfc; return val }() + case MinimuxerError.RwAfc: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$RwAfc; return val }() + case MinimuxerError.InstallApp(let _0): + return __swift_bridge__$MinimuxerError(tag: __swift_bridge__$MinimuxerError$InstallApp, payload: __swift_bridge__$MinimuxerErrorFields(InstallApp: __swift_bridge__$MinimuxerError$FieldOfInstallApp(_0: { let rustString = _0.intoRustString(); rustString.isOwned = false; return rustString.ptr }()))) + case MinimuxerError.UninstallApp: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$UninstallApp; return val }() + case MinimuxerError.CreateMisagent: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$CreateMisagent; return val }() + case MinimuxerError.ProfileInstall: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$ProfileInstall; return val }() + case MinimuxerError.ProfileRemove: + return {var val = __swift_bridge__$MinimuxerError(); val.tag = __swift_bridge__$MinimuxerError$ProfileRemove; return val }() + } + } +} +extension __swift_bridge__$MinimuxerError { + func intoSwiftRepr() -> MinimuxerError { + switch self.tag { + case __swift_bridge__$MinimuxerError$NoDevice: + return MinimuxerError.NoDevice + case __swift_bridge__$MinimuxerError$NoConnection: + return MinimuxerError.NoConnection + case __swift_bridge__$MinimuxerError$PairingFile: + return MinimuxerError.PairingFile + case __swift_bridge__$MinimuxerError$CreateDebug: + return MinimuxerError.CreateDebug + case __swift_bridge__$MinimuxerError$CreateInstproxy: + return MinimuxerError.CreateInstproxy + case __swift_bridge__$MinimuxerError$LookupApps: + return MinimuxerError.LookupApps + case __swift_bridge__$MinimuxerError$FindApp: + return MinimuxerError.FindApp + case __swift_bridge__$MinimuxerError$BundlePath: + return MinimuxerError.BundlePath + case __swift_bridge__$MinimuxerError$MaxPacket: + return MinimuxerError.MaxPacket + case __swift_bridge__$MinimuxerError$WorkingDirectory: + return MinimuxerError.WorkingDirectory + case __swift_bridge__$MinimuxerError$Argv: + return MinimuxerError.Argv + case __swift_bridge__$MinimuxerError$LaunchSuccess: + return MinimuxerError.LaunchSuccess + case __swift_bridge__$MinimuxerError$Detach: + return MinimuxerError.Detach + case __swift_bridge__$MinimuxerError$Attach: + return MinimuxerError.Attach + case __swift_bridge__$MinimuxerError$CreateAfc: + return MinimuxerError.CreateAfc + case __swift_bridge__$MinimuxerError$RwAfc: + return MinimuxerError.RwAfc + case __swift_bridge__$MinimuxerError$InstallApp: + return MinimuxerError.InstallApp(RustString(ptr: self.payload.InstallApp._0)) + case __swift_bridge__$MinimuxerError$UninstallApp: + return MinimuxerError.UninstallApp + case __swift_bridge__$MinimuxerError$CreateMisagent: + return MinimuxerError.CreateMisagent + case __swift_bridge__$MinimuxerError$ProfileInstall: + return MinimuxerError.ProfileInstall + case __swift_bridge__$MinimuxerError$ProfileRemove: + return MinimuxerError.ProfileRemove + default: + fatalError("Unreachable") + } + } +} +extension __swift_bridge__$Option$MinimuxerError { + @inline(__always) + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val.intoSwiftRepr() + } else { + return nil + } + } + @inline(__always) + static func fromSwiftRepr(_ val: Optional) -> __swift_bridge__$Option$MinimuxerError { + if let v = val { + return __swift_bridge__$Option$MinimuxerError(is_some: true, val: v.intoFfiRepr()) + } else { + return __swift_bridge__$Option$MinimuxerError(is_some: false, val: __swift_bridge__$MinimuxerError()) + } + } +} + + + +public class RustDirectoryEntry: RustDirectoryEntryRefMut { + var isOwned: Bool = true + + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } + + deinit { + if isOwned { + __swift_bridge__$RustDirectoryEntry$_free(ptr) + } + } +} +public class RustDirectoryEntryRefMut: RustDirectoryEntryRef { + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } +} +public class RustDirectoryEntryRef { + var ptr: UnsafeMutableRawPointer + + public init(ptr: UnsafeMutableRawPointer) { + self.ptr = ptr + } +} +extension RustDirectoryEntryRef { + public func path() -> RustString { + RustString(ptr: __swift_bridge__$RustDirectoryEntry$path(ptr)) + } + + public func parent() -> RustString { + RustString(ptr: __swift_bridge__$RustDirectoryEntry$parent(ptr)) + } + + public func isFile() -> Bool { + __swift_bridge__$RustDirectoryEntry$is_file(ptr) + } + + public func size() -> Optional { + __swift_bridge__$RustDirectoryEntry$size(ptr).intoSwiftRepr() + } + + public func children() -> RustVec { + RustVec(ptr: __swift_bridge__$RustDirectoryEntry$children(ptr)) + } +} +extension RustDirectoryEntry: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_RustDirectoryEntry$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_RustDirectoryEntry$drop(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: RustDirectoryEntry) { + __swift_bridge__$Vec_RustDirectoryEntry$push(vecPtr, {value.isOwned = false; return value.ptr;}()) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let pointer = __swift_bridge__$Vec_RustDirectoryEntry$pop(vecPtr) + if pointer == nil { + return nil + } else { + return (RustDirectoryEntry(ptr: pointer!) as! Self) + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_RustDirectoryEntry$get(vecPtr, index) + if pointer == nil { + return nil + } else { + return RustDirectoryEntryRef(ptr: pointer!) + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_RustDirectoryEntry$get_mut(vecPtr, index) + if pointer == nil { + return nil + } else { + return RustDirectoryEntryRefMut(ptr: pointer!) + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_RustDirectoryEntry$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_RustDirectoryEntry$len(vecPtr) + } +} + + +public class AfcFileManager: AfcFileManagerRefMut { + var isOwned: Bool = true + + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } + + deinit { + if isOwned { + __swift_bridge__$AfcFileManager$_free(ptr) + } + } +} +extension AfcFileManager { + class public func remove(_ path: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$AfcFileManager$remove({ let rustString = path.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() + } + + class public func createDirectory(_ path: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$AfcFileManager$create_directory({ let rustString = path.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() + } + + class public func writeFile(_ to: GenericIntoRustString, _ bytes: UnsafeBufferPointer) throws -> () { + try { let val = __swift_bridge__$AfcFileManager$write_file({ let rustString = to.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), bytes.toFfiSlice()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() + } + + class public func copyFileOutsideAfc(_ from: GenericIntoRustString, _ to: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$AfcFileManager$copy_file_outside_afc({ let rustString = from.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = to.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() + } +} +public class AfcFileManagerRefMut: AfcFileManagerRef { + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } +} +public class AfcFileManagerRef { + var ptr: UnsafeMutableRawPointer + + public init(ptr: UnsafeMutableRawPointer) { + self.ptr = ptr + } +} +extension AfcFileManagerRef { + class public func contents() -> RustVec { + RustVec(ptr: __swift_bridge__$AfcFileManager$contents()) + } +} +extension AfcFileManager: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_AfcFileManager$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_AfcFileManager$drop(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: AfcFileManager) { + __swift_bridge__$Vec_AfcFileManager$push(vecPtr, {value.isOwned = false; return value.ptr;}()) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let pointer = __swift_bridge__$Vec_AfcFileManager$pop(vecPtr) + if pointer == nil { + return nil + } else { + return (AfcFileManager(ptr: pointer!) as! Self) + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_AfcFileManager$get(vecPtr, index) + if pointer == nil { + return nil + } else { + return AfcFileManagerRef(ptr: pointer!) + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_AfcFileManager$get_mut(vecPtr, index) + if pointer == nil { + return nil + } else { + return AfcFileManagerRefMut(ptr: pointer!) + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_AfcFileManager$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_AfcFileManager$len(vecPtr) + } +} + + + +public func fetch_udid() -> Optional { + { let val = __swift_bridge__$fetch_udid(); if val != nil { return RustString(ptr: val!) } else { return nil } }() +} +public func test_device_connection() -> Bool { + __swift_bridge__$test_device_connection() +} + + +public func yeet_app_afc(_ bundle_id: GenericIntoRustString, _ ipa_bytes: UnsafeBufferPointer) throws -> () { + try { let val = __swift_bridge__$yeet_app_afc({ let rustString = bundle_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), ipa_bytes.toFfiSlice()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} +public func install_ipa(_ bundle_id: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$install_ipa({ let rustString = bundle_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} +public func remove_app(_ bundle_id: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$remove_app({ let rustString = bundle_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} + + +public func debug_app(_ app_id: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$debug_app({ let rustString = app_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} +public func attach_debugger(_ pid: UInt32) throws -> () { + try { let val = __swift_bridge__$attach_debugger(pid); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} + + +public func start_auto_mounter(_ docs_path: GenericIntoRustString) { + __swift_bridge__$start_auto_mounter({ let rustString = docs_path.intoRustString(); rustString.isOwned = false; return rustString.ptr }()) +} + + +public func start(_ pairing_file: GenericIntoRustString, _ log_path: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$start({ let rustString = pairing_file.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = log_path.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} +public func target_minimuxer_address() { + __swift_bridge__$target_minimuxer_address() +} + + +public func install_provisioning_profile(_ profile: UnsafeBufferPointer) throws -> () { + try { let val = __swift_bridge__$install_provisioning_profile(profile.toFfiSlice()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} +public func remove_provisioning_profile(_ id: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$remove_provisioning_profile({ let rustString = id.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultVoidAndErrors$ResultOk: return case __swift_bridge__$ResultVoidAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} +public func dump_profiles(_ docs_path: GenericIntoRustString) throws -> RustString { + try { let val = __swift_bridge__$dump_profiles({ let rustString = docs_path.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); switch val.tag { case __swift_bridge__$ResultStringAndErrors$ResultOk: return RustString(ptr: val.payload.ok) case __swift_bridge__$ResultStringAndErrors$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }() +} + + + + +// tell Swift the MinimuxerError enum can be thrown +// TODO: do this through swift-bridge instead of manually +extension MinimuxerError: Error {} diff --git a/Tests/minimuxerTests/minimuxerTests.swift b/Tests/minimuxerTests/minimuxerTests.swift new file mode 100644 index 0000000..d3841a2 --- /dev/null +++ b/Tests/minimuxerTests/minimuxerTests.swift @@ -0,0 +1,6 @@ +import Testing +@testable import minimuxer + +@Test func example() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. +} diff --git a/generated/minimuxer-Bridging-Header.h b/generated/minimuxer-Bridging-Header.h deleted file mode 100644 index c69a169..0000000 --- a/generated/minimuxer-Bridging-Header.h +++ /dev/null @@ -1,2 +0,0 @@ -#import "SwiftBridgeCore.h" -#import "minimuxer.h" diff --git a/module.modulemap b/module.modulemap deleted file mode 100644 index 9a125ae..0000000 --- a/module.modulemap +++ /dev/null @@ -1,6 +0,0 @@ -module minimuxer { - header "SwiftBridgeCore.h" - header "minimuxer.h" - - export * -}