1use needle::*;
2use haystack::{Span, Haystack};
3use slices::slice::{TwoWaySearcher, NaiveSearcher, SliceSearcher};
4use std::ops::Range;
5
6unsafe impl<'p> Searcher<str> for TwoWaySearcher<'p, u8> {
7 #[inline]
8 fn search(&mut self, span: Span<&str>) -> Option<Range<usize>> {
9 let (hay, range) = span.into_parts();
10 self.next(hay.as_bytes(), range)
11 }
12}
13
14unsafe impl<'p> ReverseSearcher<str> for TwoWaySearcher<'p, u8> {
15 #[inline]
16 fn rsearch(&mut self, span: Span<&str>) -> Option<Range<usize>> {
17 let (hay, range) = span.into_parts();
18 self.next_back(hay.as_bytes(), range)
19 }
20}
21
22unsafe impl<'p> Consumer<str> for NaiveSearcher<'p, u8> {
23 #[inline]
24 fn consume(&mut self, span: Span<&str>) -> Option<usize> {
25 self.consume(span.as_bytes())
26 }
27
28 #[inline]
29 fn trim_start(&mut self, hay: &str) -> usize {
30 self.trim_start(hay.as_bytes())
31 }
32}
33
34unsafe impl<'p> ReverseConsumer<str> for NaiveSearcher<'p, u8> {
35 #[inline]
36 fn rconsume(&mut self, span: Span<&str>) -> Option<usize> {
37 self.rconsume(span.as_bytes())
38 }
39
40 #[inline]
41 fn trim_end(&mut self, hay: &str) -> usize {
42 self.trim_end(hay.as_bytes())
43 }
44}
45
46macro_rules! impl_needle {
47 (<[$($gen:tt)*]> for $pat:ty) => {
48 impl<$($gen)*, H: Haystack<Target = str>> Needle<H> for $pat {
49 type Searcher = SliceSearcher<'p, u8>;
50 type Consumer = NaiveSearcher<'p, u8>;
51
52 #[inline]
53 fn into_searcher(self) -> Self::Searcher {
54 SliceSearcher::new(self.as_bytes())
55 }
56
57 #[inline]
58 fn into_consumer(self) -> Self::Consumer {
59 NaiveSearcher::new(self.as_bytes())
60 }
61 }
62 }
63}
64
65impl_needle!(<['p]> for &'p str);
66#[cfg(feature = "std")]
67impl_needle!(<['p]> for &'p String);
68impl_needle!(<['q, 'p]> for &'q &'p str);