FunctionCallable
@dynamicCallable
public struct FunctionCallable : Sendable
为用户函数启用以下语法糖的结构:
guard case let .int32(sum) = try await user.functions.sum([1, 2, 3, 4, 5]) else {
return
}
动态成员名称(上例中为sum
)由与函数名称直接关联的@dynamicMemberLookup
提供。
-
允许
Future<AnyBSON, Error>
可调用返回的 @DynamicCallable 实现。let cancellable = user.functions.sum(1, 2, 3, 4, 5) .sink(receiveCompletion: { result in }, receiveValue: { value in // Returned value from function })
声明
-
dynamicallyCall(withArguments:
异步(Asynchronous)) 允许
async await
可调用返回的 @DynamicMemberLookup 的实施。guard case let .int32(sum) = try await user.functions.sum(1, 2, 3, 4, 5) else { return }