How to get a slice from Vec<T> in Rust?
Hello everyone! I just started learning Rust and ran into a problem when working with vectors. I have a `Vec`, and I need to pass part of its data to a function that takes a slice `&[u32]`. I tried to do this in different ways, but I keep getting compilation errors.
Here is an example of my code:
```rust
fn main() {
let numbers = vec![10, 20, 30, 40, 50];
// Want to get a slice of the first three elements
let slice = &numbers[0..3];
// Function that takes a slice
process_slice(slice);
}
fn process_slice(data: &[u32]) {
for &item in data {
println!("{}", item);
}
}
```
This code works, but I don't understand some details. For example:
1. What is the difference between `&vec[..]` and `vec.as_slice()`? Do they do the same thing?
2. Ka