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