Closed
Description
As titled. Although slices support the a[b]
operator, it does not implement Index<uint, T>
, so one cannot pass in a slice in the following example:
fn do_something<V: Clone, T: Collection + Index<uint, V>>(t: &T) -> Vec<V> {
let mut v = Vec::with_capacity(t.len());
for i in range(0, t.len()) {
v.push((*t)[i].clone());
}
v
}
fn main() {
println!("{}", do_something(&vec![1u,2,3])); // works
println!("{}", do_something(&&[1u,2,3])); // does not work
}
Metadata
Metadata
Assignees
Labels
No labels