Consider this pattern:
fn find_index(a: &[i32], extra_info: T) -> Option<usize> {
// ...
Some(4) // or whatever
}
fn foo() {
let mut v = Vec::new();
loop {
match find_index(&v[], some_stuff) {
Some(i) => v.insert(i, other_stuff),
None => break,
}
}
}
In rust, this panics if i == v.len(), meaning that in that example we'd have to explicitly check for that case and use v.push(other_stuff) instead, while I think in many languages, the vector/array/list's insert method allows that case and implements it as identical to Vec::push.
I'd like to propose that rust's Vec do that too, and I'd be happy to write a PR if someone can point me toward the code and tests that need to be changed.
Consider this pattern:
In rust, this panics if
i == v.len(), meaning that in that example we'd have to explicitly check for that case and usev.push(other_stuff)instead, while I think in many languages, the vector/array/list's insert method allows that case and implements it as identical toVec::push.I'd like to propose that rust's Vec do that too, and I'd be happy to write a PR if someone can point me toward the code and tests that need to be changed.