Debian Codegraph @

third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CallbackInterfaceTemplate.swift

raw
1 {%- let cbi = ci.get_callback_interface_definition(name).unwrap() %}
2 {%- let callback_handler = format!("uniffiCallbackHandler{}", name) %}
3 {%- let callback_init = format!("uniffiCallbackInit{}", name) %}
4 {%- let methods = cbi.methods() %}
5 {%- let protocol_name = type_name.clone() %}
6 {%- let protocol_docstring = cbi.docstring() %}
7 {%- let vtable = cbi.vtable() %}
8 {%- let vtable_methods = cbi.vtable_methods() %}
9 {%- let ffi_init_callback = cbi.ffi_init_callback() %}
10
11 {% include "Protocol.swift" %}
12 {% include "CallbackInterfaceImpl.swift" %}
13
14 // FfiConverter protocol for callback interfaces
15 #if swift(>=5.8)
16 @_documentation(visibility: private)
17 #endif
18 fileprivate struct {{ ffi_converter_name }} {
19 fileprivate static let handleMap = UniffiHandleMap<{{ type_name }}>()
20 }
21
22 #if swift(>=5.8)
23 @_documentation(visibility: private)
24 #endif
25 extension {{ ffi_converter_name }} : FfiConverter {
26 typealias SwiftType = {{ type_name }}
27 typealias FfiType = UInt64
28
29 #if swift(>=5.8)
30 @_documentation(visibility: private)
31 #endif
32 public static func lift(_ handle: UInt64) throws -> SwiftType {
33 try handleMap.get(handle: handle)
34 }
35
36 #if swift(>=5.8)
37 @_documentation(visibility: private)
38 #endif
39 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
40 let handle: UInt64 = try readInt(&buf)
41 return try lift(handle)
42 }
43
44 #if swift(>=5.8)
45 @_documentation(visibility: private)
46 #endif
47 public static func lower(_ v: SwiftType) -> UInt64 {
48 return handleMap.insert(obj: v)
49 }
50
51 #if swift(>=5.8)
52 @_documentation(visibility: private)
53 #endif
54 public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
55 writeInt(&buf, lower(v))
56 }
57 }
58
59 {#
60 We always write these public functions just in case the callback is used as
61 an external type by another crate.
62 #}
63 #if swift(>=5.8)
64 @_documentation(visibility: private)
65 #endif
66 public func {{ ffi_converter_name }}_lift(_ handle: UInt64) throws -> {{ type_name }} {
67 return try {{ ffi_converter_name }}.lift(handle)
68 }
69
70 #if swift(>=5.8)
71 @_documentation(visibility: private)
72 #endif
73 public func {{ ffi_converter_name }}_lower(_ v: {{ type_name }}) -> UInt64 {
74 return {{ ffi_converter_name }}.lower(v)
75 }