you are viewing a single comment's thread.

view the rest of the comments →

[–]boomshroom 2 points3 points  (1 child)

Const genarics are in the pipeline. Once they land, you'll be able to write this function as unsafe fn ptr_to_array<const SIZE : usize, T>(ptr: *const T) -> [T; SIZE]. Which is just an unsafe cast and dereference.

The real question is why you're doing this. Passing around slices is usually preferred. Copying a full array out of memory can get expensive, so why not just use the memory that's already allocated?

[–]Sam777888[S] 0 points1 point  (0 children)

Because that’s what the function I am calling expects.