slice_from_ptr

Function slice_from_ptr 

Source
pub unsafe fn slice_from_ptr<'a, T>(
    ptr: *const T,
    len: usize,
) -> SecurityResult<&'a [T]>
Expand description

Safely creates a slice from a raw pointer after validation.

§Safety

This function is unsafe because:

  • The caller must ensure the pointer points to valid memory
  • The memory must not be modified during the lifetime of the returned slice
  • The memory must be valid for the entire length

§Example

use ruvector_security::ffi::slice_from_ptr;

let data = vec![1i16, 2, 3, 4];
let ptr = data.as_ptr();

// SAFETY: We own `data` and know the pointer is valid
let slice = unsafe { slice_from_ptr(ptr, data.len())? };
assert_eq!(slice, &[1, 2, 3, 4]);

§Errors

Returns an error if pointer validation fails.