2
我想用可克隆迭代器对象定义一个结构。到目前为止,我已经达到了:Clonable迭代器特质对象
pub struct UseClonableIterator2<'a,T:'a> {
it: &'a (Iterator<Item=T> + Clone)
}
这并不编译,因为Clone
不是“内置的特质”:
x.rs:2:33: 2:38 error: only the builtin traits can be used as closure or object bounds [E0225]
x.rs:2 it: &'a (Iterator<Item=T> + Clone)
^~~~~
x.rs:2:33: 2:38 help: run `rustc --explain E0225` to see a detailed explanation
一种选择可能是添加另一种类型参数的迭代器,但这使定义变得复杂,我宁愿避免它。