@@ -131,7 +131,11 @@ A hay can *borrowed* from a haystack.
131
131
pub trait Haystack : Deref <Target : Hay > + Sized {
132
132
fn empty () -> Self ;
133
133
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
+ }
135
139
136
140
fn restore_range (
137
141
& self ,
@@ -269,7 +273,7 @@ pub unsafe trait DoubleEndedSearcher<A: Hay + ?Sized>: ReverseSearcher<A> {}
269
273
with invalid ranges. Implementations of these methods often start with:
270
274
271
275
``` 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 >> {
273
277
let (hay , range ) = span . into_parts ();
274
278
// search for pattern from `hay` restricted to `range`.
275
279
}
@@ -285,13 +289,13 @@ The `.consume()` method will is similar, but anchored to the start of the span.
285
289
let span = unsafe { Span :: from_parts (" CDEFG" , 3 .. 8 ) };
286
290
// we can find "CD" at the start of the span.
287
291
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 ));
289
293
// we can only find "EF" in the middle of the span.
290
294
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 );
292
296
// we cannot find "GH" in the span.
293
297
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 );
295
299
```
296
300
297
301
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.
1629
1633
the core type `& A ` only , we could keep `SharedHaystack ` unstable longer
1630
1634
(a separate track from the main Pattern API ) until this question is resolved .
1631
1635
1636
+ * With a benefit of type checking , we may still want to split `Consumer ` from `Searcher `.
1637
+
1632
1638
[RFC 528 ]: https : // github.com/rust-lang/rfcs/pull/528
1633
1639
[RFC 1309 ]: https : // github.com/rust-lang/rfcs/pull/1309
1634
1640
[RFC 1672 ]: https : // github.com/rust-lang/rfcs/pull/1672
0 commit comments