14
14
* limitations under the License.
15
15
*/
16
16
17
- /// A `ServerInterceptorOperation ` describes to which RPCs a server interceptor should be applied.
17
+ /// A `ServerInterceptorPipelineOperation ` describes to which RPCs a server interceptor should be applied.
18
18
///
19
19
/// You can configure a server interceptor to be applied to:
20
20
/// - all RPCs and services;
21
21
/// - requests directed only to specific services registered with your server; or
22
22
/// - requests directed only to specific methods (of a specific service).
23
23
///
24
24
/// - SeeAlso: ``ServerInterceptor`` for more information on server interceptors, and
25
- /// ``ClientInterceptorOperation `` for the client-side version of this type.
26
- public struct ServerInterceptorOperation : Sendable {
27
- /// The subject of a ``ServerInterceptorOperation ``.
25
+ /// ``ClientInterceptorPipelineOperation `` for the client-side version of this type.
26
+ public struct ServerInterceptorPipelineOperation : Sendable {
27
+ /// The subject of a ``ServerInterceptorPipelineOperation ``.
28
28
/// The subject of an interceptor can either be all services and methods, only specific services, or only specific methods.
29
29
public struct Subject : Sendable {
30
30
internal enum Wrapped : Sendable {
31
31
case all
32
- case services( [ ServiceDescriptor ] )
33
- case methods( [ MethodDescriptor ] )
32
+ case services( Set < ServiceDescriptor > )
33
+ case methods( Set < MethodDescriptor > )
34
34
}
35
35
36
36
private let wrapped : Wrapped
@@ -41,19 +41,20 @@ public struct ServerInterceptorOperation: Sendable {
41
41
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified services.
42
42
/// - Parameters:
43
43
/// - services: The list of service names for which this interceptor should intercept RPCs.
44
- /// - Returns: A ``ServerInterceptorOperation ``.
45
- public static func services( _ services: [ ServiceDescriptor ] ) -> Self {
44
+ /// - Returns: A ``ServerInterceptorPipelineOperation ``.
45
+ public static func services( _ services: Set < ServiceDescriptor > ) -> Self {
46
46
Self ( wrapped: . services( services) )
47
47
}
48
48
49
49
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified service methods.
50
50
/// - Parameters:
51
51
/// - methods: The list of method descriptors for which this interceptor should intercept RPCs.
52
- /// - Returns: A ``ServerInterceptorOperation ``.
53
- public static func methods( _ methods: [ MethodDescriptor ] ) -> Self {
52
+ /// - Returns: A ``ServerInterceptorPipelineOperation ``.
53
+ public static func methods( _ methods: Set < MethodDescriptor > ) -> Self {
54
54
Self ( wrapped: . methods( methods) )
55
55
}
56
56
57
+ @usableFromInline
57
58
internal func applies( to descriptor: MethodDescriptor ) -> Bool {
58
59
switch self . wrapped {
59
60
case . all:
@@ -71,7 +72,8 @@ public struct ServerInterceptorOperation: Sendable {
71
72
/// The interceptor specified for this operation.
72
73
public let interceptor : any ServerInterceptor
73
74
74
- private let subject : Subject
75
+ @usableFromInline
76
+ internal let subject : Subject
75
77
76
78
private init ( interceptor: any ServerInterceptor , appliesTo: Subject ) {
77
79
self . interceptor = interceptor
@@ -82,15 +84,16 @@ public struct ServerInterceptorOperation: Sendable {
82
84
/// - Parameters:
83
85
/// - interceptor: The ``ServerInterceptor`` to register with the server.
84
86
/// - subject: The ``Subject`` to which the `interceptor` applies.
85
- /// - Returns: A ``ServerInterceptorOperation ``.
87
+ /// - Returns: A ``ServerInterceptorPipelineOperation ``.
86
88
public static func apply( _ interceptor: any ServerInterceptor , to subject: Subject ) -> Self {
87
89
Self ( interceptor: interceptor, appliesTo: subject)
88
90
}
89
91
90
- /// Returns whether this ``ServerInterceptorOperation `` applies to the given `descriptor`.
92
+ /// Returns whether this ``ServerInterceptorPipelineOperation `` applies to the given `descriptor`.
91
93
/// - Parameter descriptor: A ``MethodDescriptor`` for which to test whether this interceptor applies.
92
94
/// - Returns: `true` if this interceptor applies to the given `descriptor`, or `false` otherwise.
93
- public func _applies( to descriptor: MethodDescriptor ) -> Bool {
95
+ @inlinable
96
+ internal func applies( to descriptor: MethodDescriptor ) -> Bool {
94
97
self . subject. applies ( to: descriptor)
95
98
}
96
99
}
0 commit comments