[英]Rust constraints for generic types Item
While looking through the documentation for flatten .在查看flatten的文档时。
pub struct Flatten<I>
where
I: Iterator,
<I as Iterator>::Item: IntoIterator,
I was wondering why this is needed -- the last line.我想知道为什么需要这样做——最后一行。 Would the following not be sufficient?
以下还不够吗?
I::Item: IntoIterator,
After all I
is constrained to be Iterator
on the line before.毕竟
I
被限制为Iterator
就行了。
This is not necessary, indeed, and the actual code uses completely another form (an unstable Trait<Assoc: Trait>
syntax, similar to the equality syntax Trait<Assoc = Type>
).事实上,这不是必需的,实际代码完全使用另一种形式(不稳定的
Trait<Assoc: Trait>
语法,类似于相等语法Trait<Assoc = Type>
)。 It is just rustdoc showing that, because in theory you could have a type parameter implementing two traits that both have the same associated item.这只是 rustdoc 显示的,因为理论上你可以有一个类型参数来实现两个具有相同关联项的特征。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.