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 DoubleEndedIterators:
matches/rmatchesmatch_indices/rmatch_indicesmatch_ranges/rmatch_rangessplit/rsplitsplit_terminator/rsplit_terminatorsplitn/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);