Debian Codegraph @

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

raw
1 #if swift(>=5.8)
2 @_documentation(visibility: private)
3 #endif
4 fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer {
5 typealias SwiftType = {{ type_name }}
6
7 public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
8 guard let value = value else {
9 writeInt(&buf, Int8(0))
10 return
11 }
12 writeInt(&buf, Int8(1))
13 {{ inner_type|write_fn }}(value, into: &buf)
14 }
15
16 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
17 switch try readInt(&buf) as Int8 {
18 case 0: return nil
19 case 1: return try {{ inner_type|read_fn }}(from: &buf)
20 default: throw UniffiInternalError.unexpectedOptionalTag
21 }
22 }
23 }