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

public typealias SpanRef = RustBridge.SpanRef

public typealias SpanRefMut = RustBridge.SpanRefMut

// 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)
}
// swift-bridge opaque type used across Task.detached boundaries — Rust type is Send + Sync.
extension RustBridge.Span: @unchecked Sendable {}
