---
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

/// Image configuration.
public struct ImageConfig: Codable, Sendable, Hashable {
    public let language: String
    public init(language: String) {
        self.language = language
    }
    private enum CodingKeys: String, CodingKey {
        case language = "language"
    }
    public init(from decoder: any Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.language = try container.decodeIfPresent(String.self, forKey: .language) ?? ""
    }
}

// MARK: - Internal FFI conversions for ImageConfig
internal extension ImageConfig {
    init(_ rb: RustBridge.ImageConfigRef) throws {
        self.language = rb.language().toString()
    }
    func intoRust() throws -> RustBridge.ImageConfig {
        return RustBridge.ImageConfig(RustString(self.language))
    }
}

/// Result of extraction.
public struct ProcessingResult: Codable, Sendable, Hashable {
    public let text: String
    public init(text: String) {
        self.text = text
    }
    private enum CodingKeys: String, CodingKey {
        case text = "text"
    }
    public init(from decoder: any Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.text = try container.decodeIfPresent(String.self, forKey: .text) ?? ""
    }
}

// MARK: - Internal FFI conversions for ProcessingResult
internal extension ProcessingResult {
    init(_ rb: RustBridge.ProcessingResultRef) throws {
        self.text = rb.text().toString()
    }
    func intoRust() throws -> RustBridge.ProcessingResult {
        return RustBridge.ProcessingResult(RustString(self.text))
    }
}

// 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 imageConfigFromJson(_ json: String) throws -> ImageConfig {
    let data = json.data(using: .utf8) ?? Data()
    return try JSONDecoder().decode(ImageConfig.self, from: data)
}

public func processingResultFromJson(_ json: String) throws -> ProcessingResult {
    let data = json.data(using: .utf8) ?? Data()
    return try JSONDecoder().decode(ProcessingResult.self, from: data)
}

// MARK: - Trait Bridge Registration Forwarders
// Top-level `public func` re-exports of the swift-bridge–generated
// `register_*` / `unregister_*` / `clear_*` plugin registration entry
// points so consumers do not need to `import RustBridge` for plugin work.

/// Register an inbound `ImageProcessor` plugin implementation. The Swift
/// host wraps a `ImageProcessor` conformer in a `SwiftImageProcessorBox` adapter
/// (see `Sources/RustBridge/Plugins.swift`); pass the wrapped instance to
/// register the plugin in the global registry.
public func registerImageProcessor(_ swiftBox: SwiftImageProcessorBox) throws {
    try RustBridge.registerImageProcessor(swiftBox)
}

/// Unregister a previously-registered `ImageProcessor` plugin by name.
public func unregisterImageProcessor(_ name: String) throws {
    try RustBridge.unregisterImageProcessor(name)
}

// swift-bridge opaque type used across Task.detached boundaries — Rust type is Send + Sync.
extension RustBridge.ImageConfig: @unchecked Sendable {}
// swift-bridge opaque type used across Task.detached boundaries — Rust type is Send + Sync.
extension RustBridge.ProcessingResult: @unchecked Sendable {}
