slice_group_by/linear_str_group/
linear_str_group.rs

1use crate::{LinearStrGroupBy, LinearStrGroupByMut};
2
3/// An iterator that will return non-overlapping groups of equal `char`
4/// in the `str` using *linear/sequential search*.
5///
6/// It will use the `char` [`PartialEq::eq`] function.
7///
8/// [`PartialEq::eq`]: https://doc.rust-lang.org/std/primitive.char.html#impl-PartialEq%3Cchar%3E
9pub struct LinearStrGroup<'a>(LinearStrGroupBy<'a, fn(char, char) -> bool>);
10
11impl<'a> LinearStrGroup<'a> {
12    pub fn new(string: &'a str) -> Self {
13        LinearStrGroup(LinearStrGroupBy::new(string, |a, b| a == b))
14    }
15}
16
17str_group_by_wrapped!{ struct LinearStrGroup, &'a str }
18
19/// An iterator that will return non-overlapping *mutable* groups of equal `char`
20/// in the `str` using *linear/sequential search*.
21///
22/// It will use the `char` [`PartialEq::eq`] function.
23///
24/// [`PartialEq::eq`]: https://doc.rust-lang.org/std/primitive.char.html#impl-PartialEq%3Cchar%3E
25pub struct LinearStrGroupMut<'a>(LinearStrGroupByMut<'a, fn(char, char) -> bool>);
26
27impl<'a> LinearStrGroupMut<'a> {
28    pub fn new(string: &'a mut str) -> LinearStrGroupMut {
29        LinearStrGroupMut(LinearStrGroupByMut::new(string, |a, b| a == b))
30    }
31
32    #[inline]
33    pub fn as_str_mut(&mut self) -> &mut str {
34        self.0.as_str_mut()
35    }
36}
37
38str_group_by_wrapped!{ struct LinearStrGroupMut, &'a mut str }