swift-primitives/swift-equation-primitives
Equation.Protocol — equality with borrowing parameters, so ~Copyable types can compare for equality without being copied. Mirrors Swift.Equatable and, on Swift 6.4 and later, is Swift.Equatable via a namespace typealias once [SE-0499](https://github.com/swiftlang/swif
Key Features
- Move-only equality —
static func == (lhs: borrowing Self, rhs: borrowing Self) -> Boollets~Copyabletypes compare equal without being consumed. - SE-0499 dual-mode — Under Swift <6.4, the package ships its own protocol fork. Under Swift 6.4+, the protocol is a typealias to
Swift.Equatable. Conformances written today work on both compiler families. - Stdlib bridges included — Standard Library Integration target re-conforms common stdlib types (
Int,String,[T],Optional,Range, …) under Swift <6.4, so SwiftEquatabletypes are alsoEquation.Protocoltypes with no per-call-site work. - Default
!=— Implement==;!=comes from the protocol's default extension.
Quick Start
A move-only token type conforms in two lines:
import Equation_Primitives
struct Token: ~Copyable {
let id: Int
}
extension Token: Equation.`Protocol` {
static func == (lhs: borrowing Token, rhs: borrowing Token) -> Bool {
lhs.id == rhs.id
}
}
let a = Token(id: 1)
let b = Token(id: 1)
let c = Token(id: 2)
let equal: Bool = a == b // true
let notEqual: Bool = a != c // true (default impl from the protocol)A Copyable type that already conforms to Swift.Equatable conforms with an empty extension — the existing == satisfies the requirement:
struct UserID: Equatable, Equation.`Protocol` {
let value: UInt64
}
// no body required — Swift.Equatable's `==` satisfies the requirementInstallation
Add the dependency to your Package.swift:
dependencies: [
.package(url: "https://github.com/swift-primitives/swift-equation-primitives.git", branch: "main")
]Add the umbrella product to your target (re-exports the protocol and the stdlib bridges):
.target(
name: "App",
dependencies: [
.product(name: "Equation Primitives", package: "swift-equation-primitives")
]
)For narrower surface, depend on Equation Primitives Core alone (protocol only, no stdlib bridges).
Requires Swift 6.3.1 and macOS 26 / iOS 26 / tvOS 26 / watchOS 26 / visionOS 26 (or the corresponding Linux / Windows toolchain).
Architecture
Three library products plus a Test Support target:
| Product | Contents | When to import | |---------|----------|----------------| | Equation Primitives | Umbrella — re-exports Core + Standard Library Integration | Most consumers | | Equation Primitives Core | Equation namespace + Equation.Protocol | Embedded contexts, or when stdlib bridges are unwanted | | Equation Primitives Standard Library Integration | Re-conformance of stdlib types under Swift <6.4 | Pulled in transitively by the umbrella | | Equation Primitives Test Support | Re-export of Tagged Primitives Test Support | Test target only |
The Standard Library Integration target's bridges are gated behind #if swift(<6.4). Under Swift 6.4 and later, stdlib types already conform to Swift.Equatable (which Equation.Protocol typealiases to) and the bridges become no-ops.
Stability
Pre-1.0. The protocol surface is intentionally small: one method (==), one default (!=), one namespace (Equation). The expected long-term shape is full retirement of the namespace once the ecosystem's minimum Swift version reaches 6.4 stable, at which point consumers use Swift.Equatable directly. The 0.1.0 tag commits to source compatibility for the dual-mode bridge until that retirement is staged.
Platform Support
| Platform | CI | Status | |------------------|-----|--------------| | macOS 26 | Yes | Full support | | Linux | Yes | Full support | | Windows | Yes | Full support | | iOS/tvOS/watchOS | — | Supported | | Swift Embedded | — | Supported |
License
Apache 2.0. See LICENSE.md.
Package Metadata
Repository: swift-primitives/swift-equation-primitives
Default branch: main
README: README.md