Trait pattern_3::needle::DoubleEndedSearcher
source · pub unsafe trait DoubleEndedSearcher<A: Hay + ?Sized>: ReverseSearcher<A> { }
Expand description
A searcher which can be searched from both end with consistent results.
Implementing this marker trait enables the following standard algorithms to
return DoubleEndedIterator
s:
matches
/rmatches
match_indices
/rmatch_indices
match_ranges
/rmatch_ranges
split
/rsplit
split_terminator
/rsplit_terminator
splitn
/rsplitn
Examples
The searcher of a character implements DoubleEndedSearcher
, while that of
a string does not.
match_indices
and rmatch_indices
are reverse of each other only for a
DoubleEndedSearcher
.
extern crate pattern_3;
use pattern_3::ext::{match_indices, rmatch_indices};
// `match_indices` and `rmatch_indices` are exact reverse of each other for a `char` needle.
let forward = match_indices("xxxxx", 'x').collect::<Vec<_>>();
let mut rev_backward = rmatch_indices("xxxxx", 'x').collect::<Vec<_>>();
rev_backward.reverse();
assert_eq!(forward, vec![(0, "x"), (1, "x"), (2, "x"), (3, "x"), (4, "x")]);
assert_eq!(rev_backward, vec![(0, "x"), (1, "x"), (2, "x"), (3, "x"), (4, "x")]);
assert_eq!(forward, rev_backward);
// this property does not exist on a `&str` needle in general.
let forward = match_indices("xxxxx", "xx").collect::<Vec<_>>();
let mut rev_backward = rmatch_indices("xxxxx", "xx").collect::<Vec<_>>();
rev_backward.reverse();
assert_eq!(forward, vec![(0, "xx"), (2, "xx")]);
assert_eq!(rev_backward, vec![(1, "xx"), (3, "xx")]);
assert_ne!(forward, rev_backward);