1919/// renamed `NSMatcher` to `Matcher`. In response, we decided to rename `Matcher` to
2020/// `Matcher`.
2121public struct Matcher < T> {
22- fileprivate var matcher : ( Expression < T > ) throws -> MatcherResult
22+ fileprivate let matcher : @ Sendable ( Expression < T > ) throws -> MatcherResult
2323
2424 /// Constructs a matcher that knows how take a given value
25- public init ( _ matcher: @escaping ( Expression < T > ) throws -> MatcherResult ) {
25+ public init ( _ matcher: @escaping @ Sendable ( Expression < T > ) throws -> MatcherResult ) {
2626 self . matcher = matcher
2727 }
2828
@@ -39,26 +39,28 @@ public struct Matcher<T> {
3939@available ( * , deprecated, renamed: " Matcher " )
4040public typealias Predicate = Matcher
4141
42+ extension Matcher : Sendable where T: Sendable { }
43+
4244/// Provides convenience helpers to defining matchers
4345extension Matcher {
4446 /// Like Matcher() constructor, but automatically guard against nil (actual) values
45- public static func define( matcher: @escaping ( Expression < T > ) throws -> MatcherResult ) -> Matcher < T > {
47+ public static func define( matcher: @escaping @ Sendable ( Expression < T > ) throws -> MatcherResult ) -> Matcher < T > {
4648 return Matcher< T> { actual in
4749 return try matcher ( actual)
4850 } . requireNonNil
4951 }
5052
5153 /// Defines a matcher with a default message that can be returned in the closure
5254 /// Also ensures the matcher's actual value cannot pass with `nil` given.
53- public static func define( _ message: String = " match " , matcher: @escaping ( Expression < T > , ExpectationMessage ) throws -> MatcherResult ) -> Matcher < T > {
55+ public static func define( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > , ExpectationMessage ) throws -> MatcherResult ) -> Matcher < T > {
5456 return Matcher< T> { actual in
5557 return try matcher ( actual, . expectedActualValueTo( message) )
5658 } . requireNonNil
5759 }
5860
5961 /// Defines a matcher with a default message that can be returned in the closure
6062 /// Unlike `define`, this allows nil values to succeed if the given closure chooses to.
61- public static func defineNilable( _ message: String = " match " , matcher: @escaping ( Expression < T > , ExpectationMessage ) throws -> MatcherResult ) -> Matcher < T > {
63+ public static func defineNilable( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > , ExpectationMessage ) throws -> MatcherResult ) -> Matcher < T > {
6264 return Matcher< T> { actual in
6365 return try matcher ( actual, . expectedActualValueTo( message) )
6466 }
@@ -70,7 +72,7 @@ extension Matcher {
7072 /// error message.
7173 ///
7274 /// Also ensures the matcher's actual value cannot pass with `nil` given.
73- public static func simple( _ message: String = " match " , matcher: @escaping ( Expression < T > ) throws -> MatcherStatus ) -> Matcher < T > {
75+ public static func simple( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > ) throws -> MatcherStatus ) -> Matcher < T > {
7476 return Matcher< T> { actual in
7577 return MatcherResult ( status: try matcher ( actual) , message: . expectedActualValueTo( message) )
7678 } . requireNonNil
@@ -80,15 +82,15 @@ extension Matcher {
8082 /// error message.
8183 ///
8284 /// Unlike `simple`, this allows nil values to succeed if the given closure chooses to.
83- public static func simpleNilable( _ message: String = " match " , matcher: @escaping ( Expression < T > ) throws -> MatcherStatus ) -> Matcher < T > {
85+ public static func simpleNilable( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > ) throws -> MatcherStatus ) -> Matcher < T > {
8486 return Matcher< T> { actual in
8587 return MatcherResult ( status: try matcher ( actual) , message: . expectedActualValueTo( message) )
8688 }
8789 }
8890}
8991
9092/// The Expectation style intended for comparison to a MatcherStatus.
91- public enum ExpectationStyle {
93+ public enum ExpectationStyle : Sendable {
9294 case toMatch, toNotMatch
9395}
9496
@@ -123,7 +125,7 @@ public struct MatcherResult {
123125public typealias PredicateResult = MatcherResult
124126
125127/// MatcherStatus is a trinary that indicates if a Matcher matches a given value or not
126- public enum MatcherStatus {
128+ public enum MatcherStatus : Sendable {
127129 /// Matches indicates if the matcher / matcher passes with the given value
128130 ///
129131 /// For example, `equals(1)` returns `.matches` for `expect(1).to(equal(1))`.
@@ -181,7 +183,7 @@ public typealias PredicateStatus = MatcherStatus
181183
182184extension Matcher {
183185 // Someday, make this public? Needs documentation
184- internal func after( f: @escaping ( Expression < T > , MatcherResult ) throws -> MatcherResult ) -> Matcher < T > {
186+ internal func after( f: @escaping @ Sendable ( Expression < T > , MatcherResult ) throws -> MatcherResult ) -> Matcher < T > {
185187 // swiftlint:disable:previous identifier_name
186188 return Matcher { actual -> MatcherResult in
187189 let result = try self . satisfies ( actual)
@@ -207,7 +209,7 @@ extension Matcher {
207209#if canImport(Darwin)
208210import class Foundation. NSObject
209211
210- public typealias MatcherBlock = ( _ actualExpression: Expression < NSObject > ) throws -> NMBMatcherResult
212+ public typealias MatcherBlock = @ Sendable ( _ actualExpression: Expression < NSObject > ) throws -> NMBMatcherResult
211213
212214/// Provides an easy upgrade path for custom Matchers to be renamed to Matchers
213215@available ( * , deprecated, renamed: " MatcherBlock " )
@@ -225,7 +227,7 @@ public class NMBMatcher: NSObject {
225227 self . init ( matcher: predicate)
226228 }
227229
228- func satisfies( _ expression: @escaping ( ) throws -> NSObject ? , location: SourceLocation ) -> NMBMatcherResult {
230+ func satisfies( _ expression: @escaping @ Sendable ( ) throws -> NSObject ? , location: SourceLocation ) -> NMBMatcherResult {
229231 let expr = Expression ( expression: expression, location: location)
230232 do {
231233 return try self . matcher ( expr)
@@ -269,7 +271,7 @@ extension MatcherResult {
269271 }
270272}
271273
272- final public class NMBMatcherStatus : NSObject {
274+ final public class NMBMatcherStatus : NSObject , Sendable {
273275 private let status : Int
274276 private init ( status: Int ) {
275277 self . status = status
0 commit comments