m-barthelemy / DockerSwift

A Swift client library for Docker
MIT License
22 stars 3 forks source link

Architecture enum vs RawRep struct #3

Open mredig opened 2 days ago

mredig commented 2 days ago

How would you feel about refactoring Architecture (and I'm sure some others) into structs conforming to RawRepresentable?

proposal:

public struct Architecture: RawRepresentable, Codable, ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
    public static let ppc64: Architecture = "ppc64"
    public static let ppc64le: Architecture = "ppc64le"
    public static let x86: Architecture = "386"
    public static let x86_64: Architecture = "x86_64"
    public static let amd64: Architecture = "amd64"
    public static let arm: Architecture = "arm"
    public static let arm64: Architecture = "arm64"
    public static let wasm: Architecture = "wasm"
    public static let loong64: Architecture = "loong64"
    public static let mips: Architecture = "mips"
    public static let mipsle: Architecture = "mipsle"
    public static let mips64: Architecture = "mips64"
    public static let mips64le: Architecture = "mips64le"
    public static let riscv64: Architecture = "riscv64"
    public static let s390x: Architecture = "s390x"

    public var rawValue: String

    public init(rawValue: String) {
        self.rawValue = rawValue
    }

    public init(stringLiteral value: String) {
        self.init(rawValue: value)
    }
}

This would seamlessly allow for future or overlooked architectures without requiring an update. I'm not aware of any requirement for exhaustive iteration of all architectures as would be more proper for an enum. Am I missing anything?

mredig commented 2 days ago

(I bring this up because x86_64 was overlooked until I added it in my fork)