Debian Codegraph @

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

raw
1 #if swift(>=5.8)
2 @_documentation(visibility: private)
3 #endif
4 fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer {
5 public static func write(_ value: {{ type_name }}, into buf: inout [UInt8]) {
6 let len = Int32(value.count)
7 writeInt(&buf, len)
8 for (key, value) in value {
9 {{ key_type|write_fn }}(key, into: &buf)
10 {{ value_type|write_fn }}(value, into: &buf)
11 }
12 }
13
14 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> {{ type_name }} {
15 let len: Int32 = try readInt(&buf)
16 var dict = {{ type_name }}()
17 dict.reserveCapacity(Int(len))
18 for _ in 0..<len {
19 let key = try {{ key_type|read_fn }}(from: &buf)
20 let value = try {{ value_type|read_fn }}(from: &buf)
21 dict[key] = value
22 }
23 return dict
24 }
25 }