coap-request-implementations 0.1.0-alpha.4

Implementations of basic CoAP requests
Documentation
/// A component that represents Uri-Path options.
///
/// This is typically either of:
/// * [`&[str]`]: the raw URI path components.
/// * [`str`]: a URI refernce in path-absolute form (starting with a slash). It will produce its
///   slash-separated segments, and end before the query identifier (question mark, `?`) or the
///   fragment identifier (hash sign, `#`) if any is present to stay within the regular URI
///   conventions.
pub trait AsUriPath {
    fn as_uri_path(&self) -> impl Iterator<Item = &str>;
}

impl<'b> AsUriPath for &[&'b str] {
    fn as_uri_path(&self) -> impl Iterator<Item = &str> {
        self.iter().map(core::ops::Deref::deref)
    }
}

impl AsUriPath for &str {
    fn as_uri_path(&self) -> impl Iterator<Item = &str> {
        assert!(self.bytes().next() == Some(b'/'));
        let slice = self
            .split('?')
            .next()
            .expect("Non-empty strings can be split")
            .split('#')
            .next()
            .expect("Non-emptyh strings can be split");
        let mut iter = slice.split('/');
        let _empty = iter.next();
        iter
    }
}