Skip to content

Commit 64c3e59

Browse files
annotate new functions + follow Swift API Design Guidelines
1 parent 8adce9f commit 64c3e59

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let dependencies: [Package.Dependency] = [
5050

5151
// This adds some build settings which allow us to map "@available(gRPCSwift 2.x, *)" to
5252
// the appropriate OS platforms.
53-
let nextMinorVersion = 1
53+
let nextMinorVersion = 2
5454
let availabilitySettings: [SwiftSetting] = (0 ... nextMinorVersion).map { minor in
5555
let name = "gRPCSwift"
5656
let version = "2.\(minor)"

Sources/GRPCCore/Call/ConditionalInterceptor.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,59 +30,61 @@
3030
public struct ConditionalInterceptor<Interceptor: Sendable>: Sendable {
3131
public struct Subject: Sendable {
3232

33-
private let predicate: @Sendable (MethodDescriptor) -> Bool
33+
private let predicate: @Sendable (_ descriptor: MethodDescriptor) -> Bool
3434

3535
/// An operation subject specifying an interceptor that applies to all RPCs across all services will be registered with this client.
3636
public static var all: Self {
37-
Self(predicate: { _ in true })
37+
Self { _ in true }
3838
}
3939

4040
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified services.
4141
///
4242
/// - Parameters:
4343
/// - services: The list of service descriptors for which this interceptor should intercept RPCs.
4444
public static func services(_ services: Set<ServiceDescriptor>) -> Self {
45-
Self(predicate: { descriptor in
45+
Self { descriptor in
4646
services.contains(descriptor.service)
47-
})
47+
}
4848
}
4949

5050
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified service methods.
5151
///
5252
/// - Parameters:
5353
/// - methods: The list of method descriptors for which this interceptor should intercept RPCs.
5454
public static func methods(_ methods: Set<MethodDescriptor>) -> Self {
55-
Self(predicate: { descriptor in
55+
Self { descriptor in
5656
methods.contains(descriptor)
57-
})
57+
}
5858
}
5959

6060
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified services or service methods.
6161
///
6262
/// - Parameters:
6363
/// - services: The list of service descriptors for which this interceptor should intercept RPCs.
6464
/// - methods: The list of method descriptors for which this interceptor should intercept RPCs.
65+
@available(gRPCSwift 2.2, *)
6566
public static func only(
6667
services: Set<ServiceDescriptor>,
6768
methods: Set<MethodDescriptor>
6869
) -> Self {
69-
Self(predicate: { descriptor in
70+
Self { descriptor in
7071
services.contains(descriptor.service) || methods.contains(descriptor)
71-
})
72+
}
7273
}
7374

7475
/// An operation subject specifying an interceptor that will be applied to all RPCs across all services for this client excluding the specified services or service methods.
7576
///
7677
/// - Parameters:
7778
/// - services: The list of service descriptors for which this interceptor should **not** intercept RPCs.
7879
/// - methods: The list of method descriptors for which this interceptor should **not** intercept RPCs.
80+
@available(gRPCSwift 2.2, *)
7981
public static func allExcluding(
8082
services: Set<ServiceDescriptor>,
8183
methods: Set<MethodDescriptor>
8284
) -> Self {
83-
Self(predicate: { descriptor in
85+
Self { descriptor in
8486
!(services.contains(descriptor.service) || methods.contains(descriptor))
85-
})
87+
}
8688
}
8789

8890
/// An operation subject specifying an interceptor that will be applied to RPCs whose ``MethodDescriptor`` satisfies a `predicate`.
@@ -96,8 +98,9 @@ public struct ConditionalInterceptor<Interceptor: Sendable>: Sendable {
9698
///
9799
/// - Parameters:
98100
/// - predicate: A `@Sendable` closure evaluated per RPC. Return `true` to intercept.
101+
@available(gRPCSwift 2.2, *)
99102
public static func allMatching(
100-
_ predicate: @Sendable @escaping (MethodDescriptor) -> Bool
103+
_ predicate: @Sendable @escaping (_ descriptor: MethodDescriptor) -> Bool
101104
) -> Self {
102105
Self(predicate: predicate)
103106
}

0 commit comments

Comments
 (0)