1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use super::Path;
use super::PathComponent;

impl<'a> PathComponent<'a> for &'a str {
    fn as_str_slice(&self) -> &str {
        self
    }
}

impl<'a> Path<'a> for &'a str {
    type Item = &'a str;
    type Iter = StrSliceIter<'a>;
    fn path(self) -> Self::Iter {
        if self.is_empty() {
            StrSliceIter::Empty
        } else {
            StrSliceIter::NonEmpty(self.split("/"))
        }
    }
}

pub enum StrSliceIter<'a> {
    Empty,
    NonEmpty(std::str::Split<'a, &'a str>),
}

impl<'a> Iterator for StrSliceIter<'a> {
    type Item = &'a str;
    fn next(&mut self) -> Option<Self::Item> {
        match *self {
            StrSliceIter::Empty => None,
            StrSliceIter::NonEmpty(ref mut inner) => inner.next(),
        }
    }
}