std::raw::Slice
is defined as :
pub struct Slice<T> {
pub data: *const T,
pub len: uint,
}
I am trying something like this:
use std::raw::Slice as RawSlice;
let a = [1i,2,3,4];
let s : RawSlice<int>= RawSlice{data: a as *const int,
len : a.len()};
This doesn't compile. error: non-scalar cast: [int, ..4] as *const int
. I am basically unable to figure out how to get a pointer to the beginning of the array.
A similar concern is: how to convert from [int] to *const int?
You can take a pointer to the first element of the array and convert it: