Some: AsyncSequence 不抛出的一般要求
Generic requirement that Some: AsyncSequence is not throwing
我想根据序列是否可以抛出的方式扩展 AsyncSequence
。 AsyncSequence
和 AsyncIteratorProtocol
都没有明确区分这些序列。然而,并发模块确实带有带有抛出和非抛出变体的具体序列。我看到的唯一通用差异是 next
非抛出序列的方法是 rethrowing。这是一个例子:
extension AsyncMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async rethrows -> Transformed?
}
}
而投掷变体是普通的 throws
:
extension AsyncThrowingMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async throws -> Transformed?
}
}
(我什至不确定 rethrows
对于不带任何参数的方法是如何可能的。唯一想到的是这种方法的柯里化表达式可以 抛出一些关于那...)
所以,问题是如何表达以下内容:
extension AsyncSequence where AsyncIterator /* is not throwing */ {
}
当 this proposal 完全实现后,您将能够通过提供一些语法糖来表达对失败序列的一致性
extension AsyncSequence where nothrow AsyncIterator {
或
struct Foo<S: nothrow AsyncSequence>
这来自当前附加到 AsyncSequence
的 @rethrows
注释
@rethrows public protocol AsyncSequence
我想根据序列是否可以抛出的方式扩展 AsyncSequence
。 AsyncSequence
和 AsyncIteratorProtocol
都没有明确区分这些序列。然而,并发模块确实带有带有抛出和非抛出变体的具体序列。我看到的唯一通用差异是 next
非抛出序列的方法是 rethrowing。这是一个例子:
extension AsyncMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async rethrows -> Transformed?
}
}
而投掷变体是普通的 throws
:
extension AsyncThrowingMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async throws -> Transformed?
}
}
(我什至不确定 rethrows
对于不带任何参数的方法是如何可能的。唯一想到的是这种方法的柯里化表达式可以 抛出一些关于那...)
所以,问题是如何表达以下内容:
extension AsyncSequence where AsyncIterator /* is not throwing */ {
}
当 this proposal 完全实现后,您将能够通过提供一些语法糖来表达对失败序列的一致性
extension AsyncSequence where nothrow AsyncIterator {
或
struct Foo<S: nothrow AsyncSequence>
这来自当前附加到 AsyncSequence
@rethrows
注释
@rethrows public protocol AsyncSequence