coap_request_implementations/
conversions.rs

1/// A component that represents Uri-Path options.
2///
3/// This is typically either of:
4/// * [`&[str]`]: the raw URI path components.
5/// * [`str`]: a URI refernce in path-absolute form (starting with a slash). It will produce its
6///   slash-separated segments, and end before the query identifier (question mark, `?`) or the
7///   fragment identifier (hash sign, `#`) if any is present to stay within the regular URI
8///   conventions.
9pub trait AsUriPath {
10    fn as_uri_path(&self) -> impl Iterator<Item = &str>;
11}
12
13impl<'b> AsUriPath for &[&'b str] {
14    fn as_uri_path(&self) -> impl Iterator<Item = &str> {
15        self.iter().map(core::ops::Deref::deref)
16    }
17}
18
19impl AsUriPath for &str {
20    fn as_uri_path(&self) -> impl Iterator<Item = &str> {
21        assert!(self.bytes().next() == Some(b'/'));
22        let slice = self
23            .split('?')
24            .next()
25            .expect("Non-empty strings can be split")
26            .split('#')
27            .next()
28            .expect("Non-emptyh strings can be split");
29        let mut iter = slice.split('/');
30        let _empty = iter.next();
31        iter
32    }
33}