Function naive_opt::string_search_indices[][src]

pub fn string_search_indices<'a, P: SearchIn<'a>>(
    haystack: &'a str,
    needle: P
) -> SearchIndices<'a, P>

Notable traits for SearchIndices<'a, P>

impl<'a, P: SearchIn<'a>> Iterator for SearchIndices<'a, P> type Item = (usize, &'a str);

An iterator over the matches of the needle in the haystack.

Examples

use naive_opt::string_search_indices;

let v: Vec<_> = string_search_indices("abc345abc901abc", "abc").collect();
assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]);

let v: Vec<_> = string_search_indices("0abcabc7", "abc").collect();
assert_eq!(v, [(1, "abc"), (4, "abc")]);

let v: Vec<_> = string_search_indices("ababa", "aba").collect();
assert_eq!(v, [(0, "aba")]); // only the first `aba`