Skip to content

Commit 07308d4

Browse files
committed
Explain ReverseSearcher and DoubleEndedSearcher.
1 parent 58741a8 commit 07308d4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

text/0000-pattern-3.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ with invalid ranges. Implementations of `.search()` often start with:
283283

284284
The trait is unsafe to implement because it needs to guarantee the returned range is valid.
285285

286+
There is a "reverse" version of the trait, which supports searching from the end
287+
with the `.rsearch()` method besides from the start.
288+
289+
Furthermore, there is a "double-ended" version, which is a marker trait saying that
290+
searching from both ends will give consistent results. The searcher of a substring needle is
291+
an example which implements `ReverseSearcher` but not `DoubleEndedSearcher`, e.g.
292+
293+
* Forward searching the needle `xx` in the haystack `xxxxx` will yield `[xx][xx]x`
294+
* Backward searching the needle `xx` in the haystack `xxxxx` will yield `x[xx][xx]`
295+
286296
### Consumer
287297

288298
A consumer provides the `.consume()` method to implement `starts_with()` and `trim_start()`. It
@@ -320,6 +330,8 @@ assert_eq!("GH".into_consumer().consume(span.clone()), None);
320330

321331
The trait also provides a `.trim_start()` method in case a faster specialization exists.
322332

333+
Similar to searchers, the consumers also have the "reverse" and "double-ended" variants.
334+
323335
### Needle
324336

325337
A needle is simply a "factory" of a searcher and consumer.

0 commit comments

Comments
 (0)