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 {%- import "macros.swift" as swift %}
5 {%- for imported_class in self.imports() %}
6 import {{ imported_class }}
9 // Depending on the consumer's build setup, the low-level FFI code
10 // might be in a separate module, or it might be compiled inline into
11 // this module. This is a bit of light hackery to work with both.
12 #if canImport({{ config.ffi_module_name() }})
13 import {{ config.ffi_module_name() }}
16 {% include "RustBufferTemplate.swift" %}
17 {% include "Helpers.swift" %}
19 // Public interface members begin here.
20 {{ type_helper_code }}
22 {%- if ci.has_async_fns() %}
23 {% include "Async.swift" %}
26 {%- for func in ci.function_definitions() %}
27 {%- include "TopLevelFunctionTemplate.swift" %}
30 private enum InitializationResult {
32 case contractVersionMismatch
33 case apiChecksumMismatch
35 // Use a global variables to perform the versioning checks. Swift ensures that
36 // the code inside is only computed once.
37 private var initializationResult: InitializationResult {
38 // Get the bindings contract version from our ComponentInterface
39 let bindings_contract_version = {{ ci.uniffi_contract_version() }}
40 // Get the scaffolding contract version by calling the into the dylib
41 let scaffolding_contract_version = {{ ci.ffi_uniffi_contract_version().name() }}()
42 if bindings_contract_version != scaffolding_contract_version {
43 return InitializationResult.contractVersionMismatch
46 {%- for (name, expected_checksum) in ci.iter_checksums() %}
47 if ({{ name }}() != {{ expected_checksum }}) {
48 return InitializationResult.apiChecksumMismatch
52 {% for fn in self.initialization_fns() -%}
56 return InitializationResult.ok
59 private func uniffiEnsureInitialized() {
60 switch initializationResult {
63 case .contractVersionMismatch:
64 fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
65 case .apiChecksumMismatch:
66 fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")