One of the things I am having difficulties in Rust is handling pointers, more specifically their usage in slices/vectors.
In C, it's possible to have a pointer to an array and make it easy to grab the first element or even increment that pointer to get the next elements inside that array.
int test_array[5] = {1, 2, 3, 10, 100};
int *p;
printing *p would give us the first element.
Now in rust, there are multiple ways in which this example can be done.
let slice: [i32;5] = [1,2,3,10,100];
unsafe{let p = slice.as_ptr();
println!("{}",*p);
}
this can also be done by Rc, Box depending on the mutability and ownership of course.
there is also .first() which returns the first element. However, i am unsure about its safety and that doesn't work with incrementing.
My question is what's the idiomatic way to handle slices elements using pointers safely? How would the C example be written Rust while insuring safety?