Skip to content

Commit 5f00210

Browse files
committed
Fix typos and addressed some review comments.
1 parent e10b004 commit 5f00210

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

text/0000-pattern-3.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ A hay can *borrowed* from a haystack.
131131
pub trait Haystack: Deref<Target: Hay> + Sized {
132132
fn empty() -> Self;
133133
unsafe fn split_around(self, range: Range<Self::Target::Index>) -> [Self; 3];
134-
unsafe fn slice_unchecked(self, range: Range<Self::Target::Index>) -> Self;
134+
135+
unsafe fn slice_unchecked(self, range: Range<Self::Target::Index>) -> Self {
136+
let [_, middle, _] = self.split_around(range);
137+
middle
138+
}
135139

136140
fn restore_range(
137141
&self,
@@ -269,7 +273,7 @@ pub unsafe trait DoubleEndedSearcher<A: Hay + ?Sized>: ReverseSearcher<A> {}
269273
with invalid ranges. Implementations of these methods often start with:
270274

271275
```rust
272-
fn search(&mut self, span: SharedSpan<&A>) -> Option<Range<A::Index>> {
276+
fn search(&mut self, span: Span<&A>) -> Option<Range<A::Index>> {
273277
let (hay, range) = span.into_parts();
274278
// search for pattern from `hay` restricted to `range`.
275279
}
@@ -285,13 +289,13 @@ The `.consume()` method will is similar, but anchored to the start of the span.
285289
let span = unsafe { Span::from_parts("CDEFG", 3..8) };
286290
// we can find "CD" at the start of the span.
287291
assert_eq!("CD".into_searcher().search(span.clone()), Some(3..5));
288-
assert_eq!("CD".into_searcher().consume(span.clone()), Some(5));
292+
assert_eq!("CD".into_consumer().consume(span.clone()), Some(5));
289293
// we can only find "EF" in the middle of the span.
290294
assert_eq!("EF".into_searcher().search(span.clone()), Some(5..7));
291-
assert_eq!("EF".into_searcher().consume(span.clone()), None);
295+
assert_eq!("EF".into_consumer().consume(span.clone()), None);
292296
// we cannot find "GH" in the span.
293297
assert_eq!("GH".into_searcher().search(span.clone()), None);
294-
assert_eq!("GH".into_searcher().consume(span.clone()), None);
298+
assert_eq!("GH".into_consumer().consume(span.clone()), None);
295299
```
296300

297301
The trait also provides a `.trim_start()` method in case a faster specialization exists.
@@ -1629,6 +1633,8 @@ Unlike this RFC, the `Extract` class is much simpler.
16291633
the core type `&A` only, we could keep `SharedHaystack` unstable longer
16301634
(a separate track from the main Pattern API) until this question is resolved.
16311635

1636+
* With a benefit of type checking, we may still want to split `Consumer` from `Searcher`.
1637+
16321638
[RFC 528]: https://github.com/rust-lang/rfcs/pull/528
16331639
[RFC 1309]: https://github.com/rust-lang/rfcs/pull/1309
16341640
[RFC 1672]: https://github.com/rust-lang/rfcs/pull/1672

0 commit comments

Comments
 (0)