index_of

Function index_of 

Source
pub fn index_of<T: PartialEq>(collection: &[T], element: T) -> isize
Expand description

Finds the position of the first occurrence of an element in a collection. Returns -1 if the element is not found.

§Arguments

  • collection - A slice of items.
  • element - The element to search for.

§Returns

  • isize - The index of the first occurrence of the element, or -1 if not found.

§Examples

use lowdash::index_of;
let collection = vec![1, 2, 3, 4, 5];
let index = index_of(&collection, 3);
assert_eq!(index, 2);
use lowdash::index_of;
let collection = vec!["apple", "banana", "cherry"];
let index = index_of(&collection, "banana");
assert_eq!(index, 1);
use lowdash::index_of;
let collection = vec![1, 2, 3, 4, 5];
let index = index_of(&collection, 6);
assert_eq!(index, -1);