Trait naive_opt::Search[][src]

pub trait Search {
    fn search<'a, P: SearchIn<'a>>(&'a self, needle: P) -> Option<usize>;
fn rsearch<'a, P: SearchIn<'a>>(&'a self, needle: P) -> Option<usize>;
fn search_indices<'a, P: SearchIn<'a>>(
        &'a self,
        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);
;
fn rsearch_indices<'a, P: SearchIn<'a>>(
        &'a self,
        needle: P
    ) -> RevSearchIndices<'a, P>

Notable traits for RevSearchIndices<'a, P>

impl<'a, P: SearchIn<'a>> Iterator for RevSearchIndices<'a, P> type Item = (usize, &'a str);
;
fn includes<'a, P: SearchIn<'a>>(&'a self, needle: P) -> bool; }

search the needle

Required methods

fn search<'a, P: SearchIn<'a>>(&'a self, needle: P) -> Option<usize>[src]

search the needle in self.

return index of self, if it found the needle. Otherwise return None.

fn rsearch<'a, P: SearchIn<'a>>(&'a self, needle: P) -> Option<usize>[src]

reverse search the needle in self.

return index of self, if it found the needle. Otherwise return None.

fn search_indices<'a, P: SearchIn<'a>>(
    &'a self,
    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);
[src]

An iterator over the matches of needle in self.

Examples

use naive_opt::Search;

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

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

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

fn rsearch_indices<'a, P: SearchIn<'a>>(
    &'a self,
    needle: P
) -> RevSearchIndices<'a, P>

Notable traits for RevSearchIndices<'a, P>

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

An reverse search iterator over the matches of needle in self.

Examples

use naive_opt::Search;

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

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

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

fn includes<'a, P: SearchIn<'a>>(&'a self, needle: P) -> bool[src]

includes the needle in self.

returns true if the given pattern matches a sub-slice of this string slice. returns false if it does not.

Loading content...

Implementations on Foreign Types

impl<'c> Search for &'c str[src]

impl<'c> Search for String[src]

Loading content...

Implementors

Loading content...