1use haystack::{Hay, Haystack};
2use std::ops::Range;
3
4unsafe impl Hay for str {
5 type Index = usize;
6
7 #[inline]
8 fn empty<'a>() -> &'a Self {
9 ""
10 }
11
12 #[inline]
13 fn start_index(&self) -> usize {
14 0
15 }
16
17 #[inline]
18 fn end_index(&self) -> usize {
19 self.len()
20 }
21
22 #[inline]
23 unsafe fn slice_unchecked(&self, range: Range<usize>) -> &Self {
24 self.get_unchecked(range)
25 }
26
27 #[inline]
28 unsafe fn next_index(&self, index: Self::Index) -> Self::Index {
29 index + self.get_unchecked(index..).chars().next().unwrap().len_utf8()
30 }
31
32 #[inline]
33 unsafe fn prev_index(&self, index: Self::Index) -> Self::Index {
34 index - self.get_unchecked(..index).chars().next_back().unwrap().len_utf8()
35 }
36}
37
38unsafe impl<'h> Haystack for &'h mut str {
39 #[inline]
40 fn empty() -> &'h mut str {
41 Self::default()
42 }
43
44 #[inline]
45 unsafe fn slice_unchecked(self, range: Range<usize>) -> Self {
46 self.get_unchecked_mut(range)
47 }
48
49 #[inline]
50 unsafe fn split_around(self, range: Range<usize>) -> [Self; 3] {
51 let (haystack, right) = self.split_at_mut(range.end);
52 let (left, middle) = haystack.split_at_mut(range.start);
53 [left, middle, right]
54 }
55
56 #[inline]
57 fn restore_range(&self, range: Range<usize>, subrange: Range<usize>) -> Range<usize> {
58 (subrange.start + range.start)..(subrange.end + range.start)
59 }
60}
61
62mod char;
63mod func;
64mod str;