我有一个增量处理Collection
的结构。
struct Foo<T: BidirectionalCollection>
where T.Iterator.Element == UInt8,
T.SubSequence: BidirectionalCollection,
T.SubSequence.Iterator.Element == T.Iterator.Element,
T.SubSequence.Index == T.Index,
T.SubSequence.IndexDistance == T.IndexDistance,
T.SubSequence.SubSequence == T.SubSequence
{
private var state: T.IndexDistance = 0
mutating func process(_ foo: T) {
// ...
}
}
我想在内部跟踪
T.IndexDistance
(例如,计算已处理的T.IndexDistance
总数)。但是,我也想将此距离与普通
UInt
进行比较,并从普通UInt
进行设置。问题是,我似乎没有找到将
UInt
转换为T.IndexDistance
的方法。 最佳答案
let someUInt: UInt = 42
let indexDistance = T.IndexDistance(IntMax(someUInt))