| 1 |
// This file was autogenerated by some hot garbage in the `uniffi` crate. |
| 2 |
// Trust me, you don't want to mess with it! |
| 3 |
|
| 4 |
// swiftlint:disable all |
| 5 |
|
| 6 |
{%- call swift::docstring_value(ci.namespace_docstring(), 0) %} |
| 7 |
|
| 8 |
{%- import "macros.swift" as swift %} |
| 9 |
import Foundation |
| 10 |
{%- for imported_class in self.imports() %} |
| 11 |
import {{ imported_class }} |
| 12 |
{%- endfor %} |
| 13 |
|
| 14 |
// Depending on the consumer's build setup, the low-level FFI code |
| 15 |
// might be in a separate module, or it might be compiled inline into |
| 16 |
// this module. This is a bit of light hackery to work with both. |
| 17 |
#if canImport({{ config.ffi_module_name() }}) |
| 18 |
import {{ config.ffi_module_name() }} |
| 19 |
#endif |
| 20 |
|
| 21 |
{% include "RustBufferTemplate.swift" %} |
| 22 |
{% include "Helpers.swift" %} |
| 23 |
{% include "HandleMap.swift" %} |
| 24 |
|
| 25 |
// Public interface members begin here. |
| 26 |
{{ type_helper_code }} |
| 27 |
|
| 28 |
{%- if ci.has_async_fns() %} |
| 29 |
{% include "Async.swift" %} |
| 30 |
{%- endif %} |
| 31 |
|
| 32 |
{%- for func in ci.function_definitions() %} |
| 33 |
{%- include "TopLevelFunctionTemplate.swift" %} |
| 34 |
{%- endfor %} |
| 35 |
|
| 36 |
private enum InitializationResult { |
| 37 |
case ok |
| 38 |
case contractVersionMismatch |
| 39 |
case apiChecksumMismatch |
| 40 |
} |
| 41 |
// Use a global variable to perform the versioning checks. Swift ensures that |
| 42 |
// the code inside is only computed once. |
| 43 |
private let initializationResult: InitializationResult = { |
| 44 |
// Get the bindings contract version from our ComponentInterface |
| 45 |
let bindings_contract_version = {{ ci.uniffi_contract_version() }} |
| 46 |
// Get the scaffolding contract version by calling the into the dylib |
| 47 |
let scaffolding_contract_version = {{ ci.ffi_uniffi_contract_version().name() }}() |
| 48 |
if bindings_contract_version != scaffolding_contract_version { |
| 49 |
return InitializationResult.contractVersionMismatch |
| 50 |
} |
| 51 |
|
| 52 |
{%- if !config.omit_checksums %} |
| 53 |
{%- for (name, expected_checksum) in ci.iter_checksums() %} |
| 54 |
if ({{ name }}() != {{ expected_checksum }}) { |
| 55 |
return InitializationResult.apiChecksumMismatch |
| 56 |
} |
| 57 |
{%- endfor %} |
| 58 |
{%- endif %} |
| 59 |
|
| 60 |
{% for fn_item in self.initialization_fns() -%} |
| 61 |
{{ fn_item }}() |
| 62 |
{% endfor -%} |
| 63 |
|
| 64 |
return InitializationResult.ok |
| 65 |
}() |
| 66 |
|
| 67 |
// Make the ensure init function public so that other modules which have external type references to |
| 68 |
// our types can call it. |
| 69 |
public func {{ ensure_init_fn_name }}() { |
| 70 |
switch initializationResult { |
| 71 |
case .ok: |
| 72 |
break |
| 73 |
case .contractVersionMismatch: |
| 74 |
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") |
| 75 |
case .apiChecksumMismatch: |
| 76 |
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
// swiftlint:enable all |