Skip to main content

position_of

Function position_of 

Source
pub fn position_of(view: &V2TypedArrayView, needle_bits: u64) -> Option<u32>
Expand description

Return the first index i where view[i] == needle under the element-type’s equality, or None if no element matches.

The needle’s bits must be the value of kind matching view.elem_type — the dispatch shell at handle_index_of_v2 enforces the kind-precondition (returns -1 on mismatch without invoking this primitive, mirroring the JS semantics that [1,2,3].indexOf("1") is -1 not an error).

Reads the underlying TypedArray<T> buffer directly via get_unchecked (no read_element indirection) — no per-iteration retain/release on heap-element kinds.

§Safety

Caller must guarantee view is a live V2TypedArrayView (produced by as_v2_typed_array) and needle_bits is a value of view.elem_type per the §2.7.5 producer-stamp contract.