json_utils/query/path/
path_for_str_slice.rs1use super::Path;
2use super::PathComponent;
3
4impl<'a> PathComponent<'a> for &'a str {
5 fn as_str_slice(&self) -> &str {
6 self
7 }
8}
9
10impl<'a> Path<'a> for &'a str {
11 type Item = &'a str;
12 type Iter = StrSliceIter<'a>;
13 fn path(self) -> Self::Iter {
14 if self.is_empty() {
15 StrSliceIter::Empty
16 } else {
17 StrSliceIter::NonEmpty(self.split("/"))
18 }
19 }
20}
21
22pub enum StrSliceIter<'a> {
23 Empty,
24 NonEmpty(std::str::Split<'a, &'a str>),
25}
26
27impl<'a> Iterator for StrSliceIter<'a> {
28 type Item = &'a str;
29 fn next(&mut self) -> Option<Self::Item> {
30 match *self {
31 StrSliceIter::Empty => None,
32 StrSliceIter::NonEmpty(ref mut inner) => inner.next(),
33 }
34 }
35}