Hi,
Say you have this function:
fn do_with_slice(items: &[i32]) {
for i in items {
println!("{}", i);
}
}
And a Vec of i32:
let v = vec![1, 2, 3];
Is it more ideomatic and/or optimal to use do_with_slice(&v);
or do_with_slice(v.as_slice());
when calling the function?
Thanks!
H2CO3
3
As far as I know, the whole point of deref coercions is to allow simply writing &v
in such situations, for example.
1 Like
system
Closed
4
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.