---
source: tests/backends_swift_snapshot_test.rs
expression: "&file.content"
---
// Generated by alef. Do not edit by hand.
// swift-format-ignore-file

import Foundation
import RustBridge
/// Source span.
public struct Span: Codable, Sendable, Hashable {
    public let startByte: UInt
    public let endByte: UInt
    public init(startByte: UInt, endByte: UInt) {
        self.startByte = startByte
        self.endByte = endByte
    }
    private enum CodingKeys: String, CodingKey {
        case startByte = "start_byte"
        case endByte = "end_byte"
    }
    public init(from decoder: any Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.startByte = try container.decodeIfPresent(UInt.self, forKey: .startByte) ?? 0
        self.endByte = try container.decodeIfPresent(UInt.self, forKey: .endByte) ?? 0
    }
}

// MARK: - Internal FFI conversions for Span
internal extension Span {
    init(_ rb: RustBridge.SpanRef) throws {
        self.startByte = rb.startByte()
        self.endByte = rb.endByte()
    }

    func intoRust() throws -> RustBridge.Span {
        return RustBridge.Span(self.startByte, self.endByte)
    }
}

/// Parse diagnostic.
public struct Diagnostic: Codable, Sendable, Hashable {
    public let message: String
    public let span: Span
    public init(message: String, span: Span) {
        self.message = message
        self.span = span
    }
    private enum CodingKeys: String, CodingKey {
        case message = "message"
        case span = "span"
    }
    public init(from decoder: any Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.message = try container.decodeIfPresent(String.self, forKey: .message) ?? ""
        self.span = try container.decode(Span.self, forKey: .span)
    }
}

// MARK: - Internal FFI conversions for Diagnostic
internal extension Diagnostic {
    init(_ rb: RustBridge.DiagnosticRef) throws {
        self.message = rb.message().toString()
        self.span = try Span(rb.span())
    }

    func intoRust() throws -> RustBridge.Diagnostic {
        return RustBridge.Diagnostic(RustString(self.message), try self.span.intoRust())
    }
}

/// Top-level processing result.
public struct ProcessResult: Codable, Sendable, Hashable {
    public let language: String
    public let diagnostics: [Diagnostic]
    public let tags: [String]
    public init(language: String, diagnostics: [Diagnostic], tags: [String]) {
        self.language = language
        self.diagnostics = diagnostics
        self.tags = tags
    }
    private enum CodingKeys: String, CodingKey {
        case language = "language"
        case diagnostics = "diagnostics"
        case tags = "tags"
    }
    public init(from decoder: any Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.language = try container.decodeIfPresent(String.self, forKey: .language) ?? ""
        self.diagnostics = try container.decodeIfPresent([Diagnostic].self, forKey: .diagnostics) ?? []
        self.tags = try container.decodeIfPresent([String].self, forKey: .tags) ?? []
    }
}

// MARK: - Internal FFI conversions for ProcessResult
internal extension ProcessResult {
    init(_ rb: RustBridge.ProcessResultRef) throws {
        self.language = rb.language().toString()
        self.diagnostics = try rb.diagnostics().map { try Diagnostic($0) }
        self.tags = rb.tags().map { $0.as_str().toString() }
    }

    func intoRust() throws -> RustBridge.ProcessResult {
        let __diagnostics = RustVec<RustBridge.Diagnostic>()
        for __elem in self.diagnostics { __diagnostics.push(value: try __elem.intoRust()) }
        let __tags = RustVec<RustString>()
        for __elem in self.tags { __tags.push(value: RustString(__elem)) }
        return RustBridge.ProcessResult(RustString(self.language), __diagnostics, __tags)
    }
}

// MARK: - From-JSON Helpers
// Public helpers that decode JSON into first-class Swift types.
// First-class struct types (Codable) use JSONDecoder directly.
// Opaque RustBridge types forward to RustBridge.

public func spanFromJson(_ json: String) throws -> Span {
    let data = json.data(using: .utf8) ?? Data()
    return try JSONDecoder().decode(Span.self, from: data)
}
public func diagnosticFromJson(_ json: String) throws -> Diagnostic {
    let data = json.data(using: .utf8) ?? Data()
    return try JSONDecoder().decode(Diagnostic.self, from: data)
}
public func processResultFromJson(_ json: String) throws -> ProcessResult {
    let data = json.data(using: .utf8) ?? Data()
    return try JSONDecoder().decode(ProcessResult.self, from: data)
}
// swift-bridge opaque type used across Task.detached boundaries — Rust type is Send + Sync.
extension RustBridge.Span: @unchecked Sendable {}
// swift-bridge opaque type used across Task.detached boundaries — Rust type is Send + Sync.
extension RustBridge.Diagnostic: @unchecked Sendable {}
// swift-bridge opaque type used across Task.detached boundaries — Rust type is Send + Sync.
extension RustBridge.ProcessResult: @unchecked Sendable {}
