Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Swift Reference Audit and Rust Porting Matrix (Maintainer Reference)

Historical planning artifact from Phase 0. For the current public migration walkthrough, use Swift to Rust.

Audited source: SoundBlaster/SpecificationCore

Revision: 7909e62da7ca0416dc24c8165bfd0e6d4cf16e57

Audit date: 2026-07-10

Evidence Scope

The audited Swift package has a library target, a macro target, and one test target. Its manifest declares Swift tools 5.10, Apple platform minimums, and dependencies on SwiftSyntax, MacroTesting, and the Swift DocC plugin.

The implementation contains 23 non-DocC Swift files in SpecificationCore, three macro implementation files, and 12 XCTest source files. The test suite includes decision, first-match, date, async, wrapper, macro, smoke, and performance test groups. This inventory is source evidence; it does not confirm the README’s coverage, latency, or concurrency claims.

Build Baseline

Command:

swift test

Toolchain:

Apple Swift version 6.4 (swiftlang-6.4.0.23.5 clang-2100.3.23.5)
Target: arm64-apple-macosx26.0

Result: FAIL before tests run. FirstMatchSpec.Builder.build() at Sources/SpecificationCore/Specs/FirstMatchSpec.swift:206 has an ambiguous call between the erased-pair initializer and generic initializer. The build also warns that Documentation.docc is unhandled by the Swift target.

This failure prevents a current pass/fail statement about the Swift test suite. It does not invalidate source-level behavior that is independently covered by specific XCTest files; it must not be ported as a Rust behavior.

Source Evidence

AreaSource pathsTest evidence
Core compositionCore/Specification.swift, Core/SpecificationOperators.swiftSpecificationCoreTests.swift
Type erasure and collection rulesCore/AnySpecification.swiftAnySpecificationPerformanceTests.swift
DecisionsCore/DecisionSpec.swift, Specs/FirstMatchSpec.swiftDecisionSpecTests.swift, FirstMatchSpecTests.swift
Context and providersContext/EvaluationContext.swift, Context/DefaultContextProvider.swift, Core/ContextProviding.swiftsmoke and wrapper tests
Built-in rulesSpecs/PredicateSpec.swift, MaxCountSpec.swift, time/date specsdate and wrapper tests
AsyncCore/AsyncSpecification.swift, Wrappers/AsyncSatisfies.swiftAsyncFeaturesTests.swift, AsyncSatisfiesWrapperTests.swift
Declarative/macro APIsWrappers/*.swift, Definitions/AutoContextSpecification.swift, SpecificationCoreMacros/*.swiftwrapper and macro tests

Capability Matrix

Swift capabilityClassificationRust destinationRationale
Specification boolean contractAdoptP1-T2Core domain abstraction
Static and, or, not compositionAdoptP1-T2Preserve boolean and short-circuit semantics
Swift &&, `, !` overloadsAdapt
PredicateSpec closure wrapperAdoptP1-T2Implement through a closure-compatible trait or adapter
Constants and collection all/anyAdoptP1-T2Preserve logical identities
AnySpecificationAdaptP1-T3Use explicit Rust trait objects and ownership bounds
DecisionSpec and boolean-result adapterAdoptP1-T3Preserve typed optional decision model
FirstMatchSpec and fallbackAdoptP1-T3Preserve priority and short-circuit behavior
FirstMatchSpec.BuilderAdaptP1-T3Avoid Swift overload ambiguity
EvaluationContext counters, flags, events, segmentsAdaptP1-T4Preserve concepts with typed/generic data
[String: Any] user dataExcludeP1-T4Replace with generic user data or deliberate typed values
Generic/static context providersAdaptP1-T4/P2-T1Keep dependency injection with Rust sharing bounds
Default provider, locks, Combine updatesExcludeP2-T1Avoid global state and Apple-specific observation
Counter and flag rulesAdaptP1-T4Retain semantics after context design is fixed
Cooldown, event, and date rulesDeferP1-T4Require clock/time representation policy
Property wrappersExcludeMigration guideRust uses explicit evaluation and Option
AsyncSpecification and async wrappersDeferP2-T2Requires runtime-neutral future/object-safety design
Swift macros and auto-contextDeferP2-T3Separate procedural macro decision and crate boundary
Domain composite examplesExcludeExamples/docsDemonstrations, not reusable core API
Combine observationExcludeNonePlatform-specific integration
README performance figuresExcludeP3-T2Re-establish with Rust benchmarks

Behavioral Contract for Rust Tests

BehaviorSwift evidenceRust requirement
AND evaluates left first and skips right after falseSpecification.swiftPreserve short-circuiting
OR evaluates left first and skips right after trueSpecification.swiftPreserve short-circuiting
NOT negates its wrapped resultSpecification.swiftPreserve boolean complement
Empty all-of is true; empty any-of is falseAnySpecification.swiftPreserve logical identities
First match wins and later pairs are not evaluatedDecisionSpecTests.swiftPreserve ordered short-circuiting
No match produces no result; fallback produces a resultFirstMatchSpecTests.swiftModel as Option and explicit fallback
Missing counter is zero; missing flag is falseEvaluationContext.swiftDocument and test if this context model is adopted
MaxCountSpec uses strict < maximum_countMaxCountSpec.swiftPreserve strict bound
Missing cooldown/event timestamp permits evaluationtime specsPreserve only after clock API exists
Cooldown threshold uses >=time specsPreserve boundary inclusivity
Date range is inclusive; missing comparison event is falsedate specsPreserve only after time policy is decided
Async evaluation can failAsyncSpecification.swiftPreserve error propagation in P2-T2

Rust specifications receive candidates by reference unless a later API decision requires ownership. This is an intentional adaptation of Swift’s by-value protocol method and is not a behavioral incompatibility.

P1-T2 Boundary

P1-T2 implements only the synchronous boolean core: trait contract, closure predicates, static composition, constants, collection identities, tests, and documentation. It excludes dynamic dispatch, decisions, context, time, providers, async, wrappers, macros, and domain examples.

Provenance and License

The audited Swift repository declares the MIT License, copyright 2025 Egor Merkushev. This Rust repository also uses MIT. The Rust implementation is an independent rewrite; copied substantial code, prose, or assets must retain the applicable copyright and license notice. Swift package dependencies are not inherited by the Rust core merely because they appear in the Swift manifest.

Relationship to Documentation Migration

The DocC migration map tracks authored documentation destinations. This audit tracks executable behavior and source classification. Both documents must be consulted before a Rust feature is declared compatible with Swift.