【发布时间】:2015-01-06 15:28:21
【问题描述】:
我不确定如何为泛型迭代器指定迭代器输出类型的界限。在 Rust 1.0 之前,我曾经能够做到这一点:
fn somefunc<A: Int, I: Iterator<A>>(xs: I) {
xs.next().unwrap().pow(2);
}
但现在,我不确定如何为迭代器的 Item 类型设置边界。
fn somefunc<I: Iterator>(xs: I) {
xs.next().unwrap().pow(2);
}
error: no method named `pow` found for type `<I as std::iter::Iterator>::Item` in the current scope
--> src/main.rs:2:28
|
2 | xs.next().unwrap().pow(2);
| ^^^
我怎样才能让它工作?
【问题讨论】:
标签: rust