Function orx_pinned_vec::utils::slice::index_of_ptr

source ·
pub fn index_of_ptr<T>(slice: &[T], element_ptr: *const T) -> Option<usize>
Expand description

Returns the index of the element with the given reference inside the slice. This method has O(1) time complexity.

§Safety

The underlying memory of the slice &[T] stays pinned as long as the reference is in scope; i.e., is not carried to different memory locations.

Therefore, it is possible and safe to compare an element’s reference to find its position in the vector.

Out of bounds checks are in place.