Hey,
So I’m working with slices of VectorN<T, D>
but I’d like to be able to handle more ‘raw’ inputs like slices of T.
Is there any easy way to convert &[T] to &[VectorN<T,D>] ? (without copying the data).
I’ve managed to do a function that does it but it’s safety heavily relies on internal storage details of VectorN which I’m not aware of:
fn raw_slice_to_vector_slice<T, D>(raw: &[T]) -> &[VectorN<T,D>]
where
D: DimName,
DefaultAllocator: Allocator<T, D>,
{
let dim = D::dim();
let len = raw.len();
assert_eq!(len % dim, 0);
let ptr = raw.as_ptr();
unsafe { std::slice::from_raw_parts(ptr as *const VectorN<T, D>, len / dim) }
}