是否可以将此impl trait返回类型更改为特征绑定?
fn combine_vecs<T: Copy>(v: Vec<T>, u: Vec<T>) -> impl Iterator<Item=T> {
v.into_iter().chain(u.into_iter()).cycle()
}
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情
fn combine_vecs<T: Copy, TI: Iterator<Item=T>>(v: Vec<T>, u: Vec<T>) -> TI {
v.into_iter().chain(u.into_iter()).cycle()
}
Run Code Online (Sandbox Code Playgroud)
但它失败并出现以下错误
expected type parameter `TI`
found struct `Cycle<std::iter::Chain<std::vec::IntoIter<T>, std::vec::IntoIter<T>>>`
Run Code Online (Sandbox Code Playgroud)
尽管该结构实现了所需的特征,但不确定为什么它会失败。
rust ×1